//使用委派事件來取得多筆指令受影響列
private void button5_Click(object sender, EventArgs e)
{
using (SqlConnection conn = new SqlConnection(strConnStr))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand())
{
//StatementCompleted事件只適用於SqlClient
cmd.StatementCompleted += new StatementCompletedEventHandler(cmd_StatementCompleted);
cmd.CommandType = CommandType.Text;
cmd.Connection = conn;
cmd.CommandText = "Insert into Test.dbo.預存程序 (No1) Values ('HHH');" +
"Update Test.dbo.預存程序 Set No1 = 'NA' Where No1='NA' or No1='HHH'";
cmd.ExecuteNonQuery();
}
}
}
private void cmd_StatementCompleted(object sender, StatementCompletedEventArgs e)
{
MessageBox.Show("影響資料筆數:" + e.RecordCount.ToString());
}
留言
張貼留言
您好,我是 Lawrence,這裡是我的開發筆記的網誌,如果你對我的文章有任何疑問或者有錯誤的話,歡迎留言讓我知道。