是C#的SqlServer连接,没对应的标签只能选择差不多的了。
public int UpdateByDataSet(DataSet ds, string strTableName)
{
try
{
SqlConnection sqlConn = new SqlConnection(strConn);
SqlDataAdapter adapter = new SqlDataAdapter();
string strsql = "select * from " + strTableName;
SqlCommand myCommand = new SqlCommand(strsql, sqlConn);
adapter.SelectCommand = myCommand;
SqlCommandBuilder myBuilder = new SqlCommandBuilder(adapter);
myBuilder.RefreshSchema(); //必须用这个来刷新
adapter.Update(ds, strTableName);
ds.AcceptChanges(); //必须有这个来让ds接受更改
return 0;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
return -1;
}
}
相关分类