例子:我在method类里面写了个all方法,如下:
       public DataTable all()
        {      
            SqlConnection lg = new SqlConnection(address);
            SqlCommand s = new SqlCommand("ProgoodsInfo",lg);
            s.CommandType = CommandType.StoredProcedure;
            lg.Open();
            s.ExecuteReader();          
            lg.Close();
            da = new SqlDataAdapter(s);   
            da.Fill(table);  
            return table;
        }
该方法返回的是datatable型的数据,然后我要在dataGridView获取该table,在dataGridView里显示查出来的数据,然后我要改数据,然后我想单击“更新”按钮,数据就改过来了,然后更新回数据库,这个 SqlCommandBuilder 该怎么写?

解决方案 »

  1.   


    public DataTable all()
      {  
      SqlConnection lg = new SqlConnection(address);
      lg.Open();
      SqlCommand s = new SqlCommand("ProgoodsInfo",lg);
      s.CommandType = CommandType.StoredProcedure;
      s.ExecuteReader();  
      da = new SqlDataAdapter(s,lg);  
      SqlCommandBuilder scb = new SqlCommandBuilder(da);
      da.Fill(table,"Stu");  
    //修改数据
      DataRow[] drs = table.Select("学号='05205020228'");
      drs[0]["年龄"] = 25;
      da.Update(table,"Stu");
      return table;
      }
      

  2.   

    dataGridView 增删改查