|
using System; |
|
using System.Collections.Generic; |
|
using System.ComponentModel; |
|
using System.Data; |
|
using System.Drawing; |
|
using System.Linq; |
|
using System.Text; |
|
using System.Threading.Tasks; |
|
using System.Windows.Forms; |
|
using System.Data.SqlClient; |
|
|
|
|
|
namespace WindowsFormsAppSQLtest |
|
{ |
|
public partial class Form1 : Form |
|
{ |
|
public Form1() |
|
{ |
|
InitializeComponent(); |
|
} |
|
|
|
private void btn_Add_Click(object sender, EventArgs e) |
|
{ |
|
SqlConnection cn = new SqlConnection(global::WindowsFormsAppSQLtest.Properties.Settings.Default.Database1ConnectionString); |
|
//SqlConnection cn = new SqlConnection(global::); |
|
try |
|
{ |
|
string sql = "INSERT INTO Table123 (Id,name,money) values(" + txtBox_ID.Text + ",'" + txtBox_Name.Text + "'," + txtBox_Money.Text + ");"; |
|
SqlCommand exeSQL = new SqlCommand(sql, cn); |
|
cn.Open(); |
|
exeSQL.BeginExecuteNonQuery(); |
|
MessageBox.Show("add a new record", "Msg", MessageBoxButtons.OK, MessageBoxIcon.Information); |
|
//this.tableTableAdapter.Fill(this.database1DataSet1.Table); |
|
this.table123TableAdapter.Fill(this.database1DataSet1.Table123); |
|
} |
|
catch (Exception ex) |
|
{ |
|
MessageBox.Show(ex.Message, "Err", MessageBoxButtons.OK, MessageBoxIcon.Error); |
|
} |
|
finally |
|
{ |
|
cn.Close(); |
|
|
|
} |
|
} |
|
|
|
private void database1DataSet1BindingSource_CurrentChanged(object sender, EventArgs e) |
|
{ |
|
|
|
} |
|
|
|
private void Form1_Load(object sender, EventArgs e) |
|
{ |
|
// TODO: 這行程式碼會將資料載入 'database1DataSet1.Table' 資料表。您可以視需要進行移動或移除。 |
|
this.table123TableAdapter.Fill(this.database1DataSet1.Table123); |
|
|
|
} |
|
} |
|
} |