帮忙下看看这代码哪里的问题
public DataSet DataSetUpdateByDataSet(DataSet ds, string strTblName)
{
SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\helperDB.mdf;Integrated Security=True;User Instance=True");
SqlDataAdapter myAdapter = new SqlDataAdapter();
SqlCommand myCommand = new SqlCommand(("select * from " + strTblName), (SqlConnection)conn);
myAdapter.SelectCommand = myCommand;
SqlCommandBuilder myCommandBuilder = new SqlCommandBuilder(myAdapter);
try
{
myAdapter.Update(ds, strTblName);
}
catch (Exception err)
{
conn.Close();
throw err;
} return ds;
}
strTblName传了个test
也就是和我数据库里面要更新的表一样,但是他报错了
Update 无法找到 TableMapping['test'] 或 DataTable“test”
你的SqlDataAdapter 与Dataset之间没有联系
你可以先myAdapter.Fill(ds),然后更新ds中strTblName表的内容,再myAdapter.Update(ds, strTblName);