SqlCommandBuilder对像来自动构建sql命令
string sConnectonString;
sConnectonString = "Password=sa;user id = sa;Initial Catalog = master;Data Source=(local)";
SqlConnection objConn = new SqlConnection(sConnectonString);
objConn.Open();
SqlDataAdapter daAuthors = new SqlDataAdapter("select * from city_users", objConn);
DataSet dsMaster = new DataSet("master");
daAuthors.FillSchema(dsMaster, SchemaType.Source, "city_users");//加载表的构架,这样在操作加载到dataset里的表时就不用重新设置主键了
daAuthors.Fill(dsMaster, "city_users");
dsMaster.Tables["city_users"].Rows[1]["user_name"] = "sql";//注意这里的Rows[1],这个1指得是在DataSet里的表里的行号,其与数据库里的行号不一致如图1
SqlCommandBuilder objCommandBuilder = new SqlCommandBuilder(daAuthors);//构建sql命令
daAuthors.Update(dsMaster, "city_users");//更新
//daAuthors.UpdateCommand = updatecomm;
//daAuthors.UpdateCommand.ExecuteNonQuery();
objConn.Close();
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)