我想从当前datagridview里面删除数据,操作成了。但是如果我想同步删除相关的几条记录,如何做呢?代码如下: string delete_No = this.dataGridView1.SelectedRows[0].Cells["编号"].Value.ToString();
string strConnect = Properties.Settings.Default.PopInfoConnectionString;
SqlConnection conConnection = new SqlConnection(strConnect);
conConnection.Open();
string cmd = "delete from [aaa] where id=" + delete_No + "";
SqlCommand com = new SqlCommand(cmd, conConnection);
{
com.ExecuteNonQuery();
this.dataGridView1.Rows.RemoveAt(this.dataGridView1.SelectedRows[0].Index);
MessageBox.Show("记录已成功删除", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
这只是删除了一个表aaa的记录。现在设计的是表bbb,表ccc都有字段del_id等于表aaa的字段ID,当删除表aaa中id=1的记录的时候,如何同步删除表bbb/ccc中字段del_id=1的记录?
string strConnect = Properties.Settings.Default.PopInfoConnectionString;
SqlConnection conConnection = new SqlConnection(strConnect);
conConnection.Open();
string cmd = "delete from [aaa] where id=" + delete_No + "";
SqlCommand com = new SqlCommand(cmd, conConnection);
{
com.ExecuteNonQuery();
this.dataGridView1.Rows.RemoveAt(this.dataGridView1.SelectedRows[0].Index);
MessageBox.Show("记录已成功删除", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
这只是删除了一个表aaa的记录。现在设计的是表bbb,表ccc都有字段del_id等于表aaa的字段ID,当删除表aaa中id=1的记录的时候,如何同步删除表bbb/ccc中字段del_id=1的记录?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货