麻烦帮我看看以下代码吧,我想用SqlCommandBuilder实现,应该怎么改呢? private void button3_Click(object sender, EventArgs e) 
        { 
            DataSet ds = new DataSet(); 
            DataTable dt = new DataTable("M"); 
            DataColumn idC = new DataColumn("TID", typeof(Int32)); 
            DataColumn mC = new DataColumn("TMoney", typeof(Int32)); 
            dt.Columns.Add(idC); 
            dt.Columns.Add(mC);             string[] list = textBox1.Text.Split(','); 
            string[] mList = textBox2.Text.Split(','); 
            for (int i = 0; i < list.Length; i++) 
            { 
                DataRow row = dt.NewRow(); 
                
                row[0] = list[i]; 
                row[1] = mList[i]; 
                dt.Rows.Add(row);                 row.AcceptChanges(); 
                row.SetModified(); 
        
                //dt.Rows[i].SetModified();             } 
            ds.Tables.Add(dt); 
            string conStr = "database=.;initial catalog=northwind;integrated security=true"; 
            SqlConnection con = new SqlConnection(conStr); 
            SqlCommand cmd = new SqlCommand();             cmd.Connection = con; 
            cmd.CommandText = "update moneytable set [money]=@m where id=@id";             SqlParameter m1 = new SqlParameter("@id", SqlDbType.Int); 
            m1.SourceColumn = "TID"; 
            cmd.Parameters.Add(m1);             SqlParameter m2 = new SqlParameter("@m", SqlDbType.Int); 
            m2.SourceColumn = "TMoney"; 
            cmd.Parameters.Add(m2);             try 
            { 
                下面应该怎么写呢? 
                SqlDataAdapter da = new SqlDataAdapter(); 
                SqlCommandBuilder builder=new SqlCommandBuilder(da); 
                da.UpdateCommand = cmd;                 int n = da.Update(ds, "M"); 
                MessageBox.Show(n.ToString()); 
            } 
            catch (Exception ex) 
            { 
                MessageBox.Show("error" + ex.Message); 
            } 
                    }

解决方案 »

  1.   

    http://dev.csdn.net/Develop/article/75/75832.shtm
      

  2.   

    try 
                { 
                   
                    SqlDataAdapter da = new SqlDataAdapter(); 
                    SqlCommandBuilder builder=new SqlCommandBuilder(da); 
                    da.UpdateCommand = cmd;                 int n = da.Update(ds, "M"); 
                    MessageBox.Show(n.ToString()); 
                } 
    就想把try里的语句用sqlcommandbuilder来实现,想知道应该怎么写,或者可行不?
      

  3.   

       
     SqlDataAdapter da = new SqlDataAdapter(); 
                   
     SqlCommandBuilder builder=new SqlCommandBuilder(da); 
                    
    da.UpdateCommand = cmd; ds.AcceptChanges(); 
    int n = da.Update(ds, "M"); int n = da.Update(ds, "M"); 
                
      

  4.   

    DataTable dt = new DataTable("M"); 这个声明后结构未知dt.Rows.Add(row);  可能要改成dt.Rows.Import(row)
      

  5.   

    da.UpdateCommand = cmd; 
    这句必须要吗?