111,094
社区成员




private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
OleDbConnection myConnection = connectionOpen();
string deleteID = dataGridView1.SelectedRows[0].Cells[0].Value.ToString(); //获取ID了就根据ID写SQL语句或者存储过程对数据库的数据进行删除
//deleteID = dataGridView1.CurrentRow.Cells[0].Value.ToString();
string mySQL = "delete * from TEST WHERE ID='" + deleteID + "'";
MessageBox.Show(mySQL, "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
myCommand = new OleDbCommand(mySQL, myConnection); //新建数据库命令。。。
int x = myCommand.ExecuteNonQuery();//返回影响行数
if (x > 0)
MessageBox.Show("删除成功!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
//如果大于0操作成功,小于等于0符合没有条件的行
else
MessageBox.Show("删除失败!可能是本数据不存在。。。", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.connectionClose(myConnection);
MainWindow_Load(null, null);
}
catch (ArgumentOutOfRangeException aore)
{
MessageBox.Show(aore.Message, "数据库更新失败");
throw;
}
}