DataGridViewCheckBoxColumn获得选中状态

biao1 2007-05-09 07:04:03
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条件怎么写?
...全文
924 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
lypbingyue 2008-09-05
  • 打赏
  • 举报
回复
up
hgs5945 2007-05-11
  • 打赏
  • 举报
回复
你要获取被选中行的主键,然后再根据主键删除数据库的行。
下面的例子的数据库主键为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("成功!");

}

}

}
biao1 2007-05-10
  • 打赏
  • 举报
回复
是啊 从昨天到现在 但愿不是在将来 呵呵
zheng616 2007-05-10
  • 打赏
  • 举报
回复
还没解决呀,晕.
biao1 2007-05-10
  • 打赏
  • 举报
回复
还没解决 继续!
biao1 2007-05-10
  • 打赏
  • 举报
回复
大家有没有更详细的办法?
QuinsonYue 2007-05-09
  • 打赏
  • 举报
回复
where colume =1;
QuinsonYue 2007-05-09
  • 打赏
  • 举报
回复
这样把 先update 再delete ..........where colume = true;

110,537

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧