最好用command来更新数据库,不要用数据集直接更新

解决方案 »

  1.   

    首先你的数据是用SqlDataAdapter填充    .fill(dataset)
    Friend WithEvents Data_con As System.Data.SqlClient.SqlConnection
        Friend WithEvents Data_adp As System.Data.SqlClient.SqlDataAdapterData_adp .update(dataset);在事件中就可以了or Data_adp.update(table)
      

  2.   

    补充一下,我用的是WinForm编程,我想在DataGrid中直接编辑数据,然后写到数据库中,请问应该怎么做啊?
      

  3.   

    private void DataBinding(string name)
       {
                 //设置查询字符串
     string commString="SELECT * From Customers WHERE "+ "ContactName="+"'"+name+"'";
     //新建一个SqlCommand对象
     SqlCommand comm=new SqlCommand() ;
         //设置SqlCommand对象的查询语句
     comm.CommandText=commString;  
     //设置SqlCommand对象的连接
     comm.Connection=this.sqlConnection1;      //新建一个数据集存贮查询结果   
       DataSet dataSet2=new DataSet();
     //改变数据适配器对象的查询语句 
     this.sqlDataAdapter1.SelectCommand=comm;
     //填充数据集
     this.sqlDataAdapter1.Fill(dataSet2,"Customers");             //具体对每个控件进行数据绑定
     //绑定前要清空以前的绑定
              this.textBox1.DataBindings.Clear();
     this.textBox1.DataBindings.Add("Text",dataSet2,"Customers.CustomerID");
     this.textBox2.DataBindings.Clear();
     this.textBox2.DataBindings.Add("Text",dataSet2,"Customers.CompanyName");
     this.textBox3.DataBindings.Clear();
     this.textBox3.DataBindings.Add("Text",dataSet2,"Customers.ContactName");
     this.textBox4.DataBindings.Clear();
     this.textBox4.DataBindings.Add("Text",dataSet2,"Customers.ContactTitle");
     this.textBox5.DataBindings.Clear();
     this.textBox5.DataBindings.Add("Text",dataSet2,"Customers.Address");
          this.textBox6.DataBindings.Clear();
       this.textBox6.DataBindings.Add("Text",dataSet2,"Customers.City");
     this.textBox7.DataBindings.Clear();
     this.textBox7.DataBindings.Add("Text",dataSet2,"Customers.Region");
     this.textBox8.DataBindings.Clear();
     this.textBox8.DataBindings.Add("Text",dataSet2,"Customers.PostalCode");
          this.textBox9.DataBindings.Clear();
     this.textBox9.DataBindings.Add("Text",dataSet2,"Customers.Country");
     this.textBox10.DataBindings.Clear();
     this.textBox10.DataBindings.Add("Text",dataSet2,"Customers.Phone");
     this.textBox11.DataBindings.Clear();
     this.textBox11.DataBindings.Add("Text",dataSet2,"Customers.Fax");
    }
      

  4.   

    http://dotnet.aspx.cc/ShowDetail.aspx?id=8ADE535F-AD40-4DE3-A962-A64B4FAF12C4
      

  5.   

    你恐怕已经有了一个DataAdapter和一个DataSet,而且DataSet中一定有一个表,暂且称它为Table1。那么可以这么做:
    DataAdapter.update(DataSet, "Table1")
    就全部OK了。
      

  6.   

    我没有用过c#
      根据我用vb的经验,把datagrid的属性
    设置成:
       allowupdate=true
    应该就可以
      至于c#嘛,就看其中的表现形式了
      

  7.   

    孟子先生那个是否太麻烦?Adapter不是有一个UpdateDataSet方法吗?而且字段少还好办,多的时候还要去建数组、循环。
      

  8.   

    http://blog.csdn.net/zhzuo/archive/2004/08/06/67037.aspx