问题描述:
  在进行数据库编程过程中,需要对datagrid中的某些行进行编辑、删除同时在需要的时候,能够增加新行??
  恳求,各位大哥帮忙了,在线等待
  给出思路或者例子。

解决方案 »

  1.   

    你可在sqlCommand和sqlDataAdapter中对数据库查询使用SQL语句来对数据库进行删除和增加,例对Northwind数据库中的customer表修改:
    删除:
             string StrSQL="DELETE FROM Customers WHERE ustomers.CustomerID='"
                  +this.textBox1.Text+"'";
    this.sqlCommand1.CommandText=StrSQL;
    this.sqlCommand1.Connection=this.sqlConnection1;
    this.sqlConnection1.Open();
    this.sqlCommand1.ExecuteNonQuery();//执行语句
    this.sqlConnection1.Close();
    //更新数据集
    this.dataSet1.Tables["Customers"].Rows[this.MyBind.Position].BeginEdit();
    this.dataSet1.Tables["Customers"].Rows[this.MyBind.Position].EndEdit();
    this.dataSet1.AcceptChanges();
    this.sqlDataAdapter1.Fill(this.dataSet1,"Customers");增加是一样的,只要用到INSERT INTO便可
      

  2.   

    可能是我描述的不够清楚,是这样的我的窗体上有一个datagrid控件,然后有增加、删除、更新按钮。当我在datagrid中单击某一行的时候,再单击“删除”按钮  可以删除此行。再点击“增加”按钮时  可以对新行录入。然后保存。
      

  3.   

    请问一下lz问题解决了么
    我现在也碰到的这样的问题
    以前vb的时候有属性可以设置,可是到了.net好像就没有哪几个属性了
      

  4.   

    lz
    看看这个帖子
    http://community.csdn.net/Expert/topic/4248/4248518.xml?temp=.540539
    不过我还没有试过
      

  5.   

    DataSet.Tables[i].DefaultView.AllowNew = false;
    DataSet.Tables[i].DefaultView.AllowDelete = false;
    DataSet.Tables[i].DefaultView.AllowEdit = true;