本人想通过CommandBuilder 编辑 DATAGRIDVIEW 返回数据库 ~ 望给出实例代码! string sqlstr = "Server =(local);database = SalesManagementSystem;uid =sa;pwd = 123";
SqlConnection sqlcon = new SqlConnection(sqlstr);
string str = "select * from T_BasicInformation_Customer";
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = new SqlCommand(str,sqlcon);
SqlCommandBuilder scb = new SqlCommandBuilder(da);
if (sqlcon.State == ConnectionState.Closed)
sqlcon.Open();
DataSet ds = new DataSet();
da.Fill(ds, "T_BasicInformation_Customer");
scb.GetUpdateCommand();
da.Update(ds,"T_BasicInformation_Customer");望大家指教纠正
你想 Update 什么?从你的代码来看,没有任何数据操作逻辑,只是提取了数据而已。
SqlConnection sqlcon = new SqlConnection(sqlstr);
string str = "select * from T_BasicInformation_Customer";
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = new SqlCommand(str,sqlcon);
SqlCommandBuilder scb = new SqlCommandBuilder(da);
if (sqlcon.State == ConnectionState.Closed)
sqlcon.Open();
DataSet ds = new DataSet();
da.Fill(ds, "T_BasicInformation_Customer");
scb.GetUpdateCommand();
da.Update(ds,"T_BasicInformation_Customer");望大家指教纠正
你想 Update 什么?从你的代码来看,没有任何数据操作逻辑,只是提取了数据而已。
把 DataRow 的状态改为 新加的就行了
SqlDataAdapter sda;SqlCommandBuilder scb = new SqlCommandBuilder(sda);
sda.Update(ds);
this.dataGridView1.DataSource = ds.Tables[0];