测过,成功。
private void btnSaveEmploy_Click(object sender, EventArgs e)
{
DataTable dt = grcAlterEmploy.DataSource as DataTable;
dt.TableName = "Employers";
DataSet set = new DataSet();
set.Tables.Add(dt);
UpdateByDataSet(set, "Employers", DbHelper.connectionString);
}
public void UpdateByDataSet(DataSet ds, string strTblName, string strConnection)
{
SqlConnection conn = new SqlConnection(strConnection);
SqlDataAdapter myAdapter = new SqlDataAdapter();
SqlCommand myCommand = new SqlCommand("select * from " + strTblName, conn);
myAdapter.SelectCommand = myCommand;
SqlCommandBuilder myCommandBuilder = new SqlCommandBuilder(myAdapter);
myAdapter.Update(ds, strTblName);
}
数据库中用sqlcommand命令