日期:2014-05-18 浏览次数:20963 次
SqlCommand cmd = new SqlCommand(string.Empty, sqlcon);
SqlTransaction tran = cmd.Transaction;
try
{
for (int i = 0; i < dataGridView1.SelectedRows.Count; i++)
{
cmd.CommandText = "delete tb1 where 序号=" + dataGridView1.SelectedRows[i].Cells[0].ToString();
cmd.ExecuteNonQuery();
}
tran.Commit();
MessageBox.Show("删除成功! ", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch(Exception ex)
{
tran.Rollback();
MessageBox.Show("删除失败! " + ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}