|
按钮调用如下方法:没有报错,但是重新检索的时候数据没有改变
public static void UpdateDataset(DataSet dataSet, string tableName,string connstr)
{
SqlConnection conn = new SqlConnection(connstr);
conn.Open();
string ls_sql = "select top 0 * from " + tableName;
SqlDataAdapter da = new SqlDataAdapter(ls_sql,conn);
SqlCommandBuilder cb = new SqlCommandBuilder(da);
DataSet ds = new DataSet();
ds.Clear();
da.Fill(ds,tableName);
ds = dataSet.Copy();
try
{
da.Update(ds,tableName);
}
catch(System.Data.SqlClient.SqlException e)
{
throw new Exception(e.Message);
}
finally
{
conn.Close();
da.Dispose();
cb.Dispose();
ds.Dispose();
dataSet.AcceptChanges();
}
} |
|