In MSSQL, how to find any row has updated or not after executing the update query? [modified]
-
Hi all, This is the code, where the problem occurs. SqlDataAdapter da = new SqlDataAdapter("UPDATE CompanyInfo SET CompName='abc' where CompID='" + CompID.Text.Trim() + "'", con); DataSet ds = new DataSet(); da.Fill(ds); int gh = da.Update(ds, "CompanyInfo"); da.Update(ds, "CompanyInfo")- fires an exception ("Update unable to find TableMapping['CompanyInfo'] or DataTable 'CompanyInfo'."). Please suggest the idea. Thanks and Regards
modified on Saturday, January 31, 2009 3:23 AM
-
Hi all, This is the code, where the problem occurs. SqlDataAdapter da = new SqlDataAdapter("UPDATE CompanyInfo SET CompName='abc' where CompID='" + CompID.Text.Trim() + "'", con); DataSet ds = new DataSet(); da.Fill(ds); int gh = da.Update(ds, "CompanyInfo"); da.Update(ds, "CompanyInfo")- fires an exception ("Update unable to find TableMapping['CompanyInfo'] or DataTable 'CompanyInfo'."). Please suggest the idea. Thanks and Regards
modified on Saturday, January 31, 2009 3:23 AM
The first thing is that the constructor of SqlDataAdapter expects to receive a SELECT string, not an UPDATE string. Also when using SqlDataAdapter you don't concatenate values to the statement (actually you should never do this. It seems that you've mixed SqlDataAdapter with SqlCommand. So: - create a proper select sattement - use that when constructing - if you want that the update statement is generated automatically, make sure that the select command contains key column from your table. Also use SqlCommandBuilder to create the select command - otherwise create a SqlCommand for UPDATE and place that in SqlDataAdapter.UpdateCommand After those steps you can try to call the Update method of the SqlDataAdapter.
The need to optimize rises from a bad design.My articles[^]
-
Hi all, This is the code, where the problem occurs. SqlDataAdapter da = new SqlDataAdapter("UPDATE CompanyInfo SET CompName='abc' where CompID='" + CompID.Text.Trim() + "'", con); DataSet ds = new DataSet(); da.Fill(ds); int gh = da.Update(ds, "CompanyInfo"); da.Update(ds, "CompanyInfo")- fires an exception ("Update unable to find TableMapping['CompanyInfo'] or DataTable 'CompanyInfo'."). Please suggest the idea. Thanks and Regards
modified on Saturday, January 31, 2009 3:23 AM
Your code is such that I could erase your database any time i wanted. Please tell me this is a student assignment and not paid work. Your code is stupid. You fill a dataset and then pass it through the data adapter - why ? You just want to run this SQL, you need no dataset for that. Are you making it up as you go along, or do you actually know somethign about C# or programming in general ?
Christian Graus Driven to the arms of OSX by Vista.
-
Hi all, This is the code, where the problem occurs. SqlDataAdapter da = new SqlDataAdapter("UPDATE CompanyInfo SET CompName='abc' where CompID='" + CompID.Text.Trim() + "'", con); DataSet ds = new DataSet(); da.Fill(ds); int gh = da.Update(ds, "CompanyInfo"); da.Update(ds, "CompanyInfo")- fires an exception ("Update unable to find TableMapping['CompanyInfo'] or DataTable 'CompanyInfo'."). Please suggest the idea. Thanks and Regards
modified on Saturday, January 31, 2009 3:23 AM
hi.... Just follow this link.... about DataAdapter