[ADO.NET 3.5] 批次更新
Introduction
撰寫一個應用程式去執行批次更新作業,並且,監看執行結果。
Example
private void Button1_Click(object sender, EventArgs e) {
using (SqlConnection cn = new SqlConnection("xxx")) {
cn.Open();
using (SqlCommand cmd = new SqlCommand()) {
//繫結事件
cmd.StatementCompleted += new StatementCompletedEventHandler(cmd_StatementCompleted);
cmd.Connection = cn;
//利用 ";" 分隔 SQL 陳述式
cmd.CommandText = "insert into dept (deptname) values('部門1');" + "update dept set deptname='新部門' where deptid > 1082";
cmd.ExecuteNonQuery();
}
}
}
void cmd_StatementCompleted(object sender, StatementCompletedEventArgs e) {
listBox1.Items.Add("影響資料筆數:" + e.RecordCount.ToString());
}
三小俠 小弟獻醜,歡迎指教