WinForm中DataGridViewCheckBoxColumn这个列,我是通过他的选中然后点button来删除一个列的,这个代码怎么写呢? 大家说说思路
我在网上找的,代码 不过不行
private void button2_Click(object sender, EventArgs e)
{ for (int i = 0; i < dataGridView1.RowCount; i++)
{
string re_value = dataGridView1.Rows[i].Cells[0].EditedFormattedValue.ToString(); if (re_value == "True")//判断勾选的
{ string strConnection = "Provider=Microsoft.Jet.OleDb.4.0;";
strConnection += "Data Source=";
strConnection += Application.StartupPath + (@"\CMT.mdb");
OleDbConnection conn = new OleDbConnection(strConnection);
conn.Open(); OleDbCommand cmd = new OleDbCommand("delete from foa_Personnel where.....", conn);
cmd.ExecuteNonQuery();
MessageBox.Show("成功!"); }
else
{
continue;
}
}
}
sql语句的where条件怎么写?
我在网上找的,代码 不过不行
private void button2_Click(object sender, EventArgs e)
{ for (int i = 0; i < dataGridView1.RowCount; i++)
{
string re_value = dataGridView1.Rows[i].Cells[0].EditedFormattedValue.ToString(); if (re_value == "True")//判断勾选的
{ string strConnection = "Provider=Microsoft.Jet.OleDb.4.0;";
strConnection += "Data Source=";
strConnection += Application.StartupPath + (@"\CMT.mdb");
OleDbConnection conn = new OleDbConnection(strConnection);
conn.Open(); OleDbCommand cmd = new OleDbCommand("delete from foa_Personnel where.....", conn);
cmd.ExecuteNonQuery();
MessageBox.Show("成功!"); }
else
{
continue;
}
}
}
sql语句的where条件怎么写?
下面的例子的数据库主键为t_id;private void button2_Click(object sender, EventArgs e)
{for (int i = 0; i < dataGridView1.RowCount; i++)
{
string re_value = dataGridView1.Rows[i].Cells[0].EditedFormattedValue.ToString();if (re_value == "True")//判断勾选的
{
string id==dataGridView1.Rows[i].Cells["t_id"].Value.ToString().Trim();
string strConnection = "Provider=Microsoft.Jet.OleDb.4.0;";
strConnection += "Data Source=";
strConnection += Application.StartupPath + (@"\CMT.mdb");
OleDbConnection conn = new OleDbConnection(strConnection);
conn.Open();OleDbCommand cmd = new OleDbCommand("delete from foa_Personnel where [t_id]='" + id + "'", conn);
cmd.ExecuteNonQuery();
MessageBox.Show("成功!");}}}