Update unable to find TableMapping['Table'] or DataTable 'Table'
I use northwind database,
The cod is bellow:
Thanks ahead!
string
uid = (string)(Session["uid"]); MyConnection = new SqlConnection();MyConnection.ConnectionString =
"Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\NORTHWND.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"; SqlDataAdapter custDA = new SqlDataAdapter("SELECT CustomerID,CompanyName FROM Customers",MyConnection);custDA.UpdateCommand=
new SqlCommand("UPDATE Customers SET CompanyName=@CompanyName WHERE CustomerID=@CustomerID",MyConnection);custDA.UpdateCommand.Parameters.Add(
"@CompanyName",SqlDbType.NVarChar,15,"CompanyName"); SqlParameter workParm=custDA.UpdateCommand.Parameters.Add("@CustomerID",SqlDbType.NChar,5,"CustomerID");workParm.SourceColumn=
"CustomerID";workParm.SourceVersion=
DataRowVersion.Original;workParm.Value = uid;
DataSet custDS = new DataSet();custDA.Fill(custDS,
"Customers"); DataRow cRow = custDS.Tables["Customers"].Rows[0];cRow[
"CompanyName"]="new Category";custDA.Update(custDS)
Replies
Know the answer? Post it — somebody with the same question will find it here.