+ -
当前位置:首页 → 问答吧 → 怎么删除DataGridView中的一行数据

怎么删除DataGridView中的一行数据

时间:2011-12-10

来源:互联网

点击button的时候,怎么删除DataGridView中的一行数据
  
  C# code
 int index = 0;//dataGridView1中ID列的索引
            string temp = string.Format("delete goods where ID={0}",
            dataGridView1[index, dataGridView1.SelectedCells[0].RowIndex].Value);
            dataGridView1.Rows.RemoveAt(dataGridView1.SelectedCells[0].RowIndex);

这样只能在显示时删除表面的,但是数据库里还是没删除该行数据啊

作者: xiaogediao   发布时间: 2011-12-10

它们不是联动的,删除row的时候,直接sql语句删除 delete * from xxxx

作者: bdmh   发布时间: 2011-12-10

你只是删了查询出来的一行显示数据,而真正影响到数据库的只有下SQL delete才行.

作者: aganqin   发布时间: 2011-12-10

可以直接选中一行,然后del就行了。。不过,如果想在后台数据库也删掉数据的话,必须得加上代码。[code=C#][/code]SqlCommandBuilder scb = new SqlCommandBuilder(sda);
  sda.Update(ds, "course");

作者: happyfsyy   发布时间: 2011-12-10

嗯 我就是想同时删除数据库的行数据
C# code

   private void button4_Click(object sender, EventArgs e)
        {
            mycon = new SqlConnection(constr);
            int index = 0;//dataGridView1中ID列的索引
            string temp = string.Format("delete goods where ID={0}",
            dataGridView1[index, dataGridView1.SelectedCells[0].RowIndex].Value);
            dataGridView1.Rows.RemoveAt(dataGridView1.SelectedCells[0].RowIndex);
            SqlDataAdapter da = new SqlDataAdapter("delete goods where id={0}", mycon);
            DataSet ds = new DataSet();
            da.Fill(ds);
            SqlCommandBuilder scb = new SqlCommandBuilder(da);
              da.Update(ds, "course");
            

          
        }



但是还是有异常 “0”附近有错误!

作者: xiaogediao   发布时间: 2011-12-10

就如一楼所说的

作者: Xia5523   发布时间: 2011-12-10

我想请问LZ的 temp 变量 在哪里执行?
你只是写了一个delete语句,却没有提交执行

作者: keenweiwei   发布时间: 2011-12-10

相关阅读 更多

热门下载

更多