Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Database Update error

Status
Not open for further replies.

goneWildCoder

Programmer
May 26, 2004
20
0
0
US
Hi all,

I am getting the following error when trying to update database table:

"Error: Update unable to find TableMapping['Table'] or DataTable 'Table'.

Here is the code snippet that is throwing the error (specifically, the Update() command )

if (upDateFlag)
{
//update
SqlConnection dataConnection = new SqlConnection("Integrated Security=true;" +
"Initial Catalog=SPIRIT2TEST;" + "DataSource=TECHSERVER") ;

SqlDataAdapter adap = new SqlDataAdapter("SELECT * FROM Dept", dataConnection);

adap.Update(changedDataDs, "Dept");
ds.AcceptChanges();

}

catch (Exception e)
{}

Can you please point out what I might be doing wrong...

Thanks

 
My guess is that you're not providing the update command. You need to create a sqlCommandBuilder after you create the data adapter. Place this line right after the line you instanced the data adapter:

SqlCommandBuilder foo = new SqlCommandBuilder(adap);

You shouldn't have to do anything else. This will create the update, insert, and delete statements in your data adapter that it needs to do the update. The command builder uses the existing select statement of the data adapter to figure out how to create the other statements.
 
Stat792,

I tried it....i also tried adding the update command manually:

SqlCommandBuilder foo = new SqlCommandBuilder(adap);
adap.UpdateCommand = foo.GetUpdateCommand.CommandText;

However, I still get the error.....

Please help!1
 
My first post still stands, you'll need to set the update related commands to update. But looking at the error, it seems like there is a problem with your dataset. Can you include the code you used to create / load it?

It kinda looks like the data adapter is expecting a table named 'Table' which is the defalt name for an untyped data set if I remember correctly. Did you maybe name the table at some point or use a typed data set that named it?

Anyways, just post the code where you create and fill that dataset and I bet the issue is there.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top