update database from dataset

S

skneife

I need to use the dataAdapter.Update to update all tables of a
dataset.
Look at the code below, I load my dataset by DataFile.xml and I update
the database by callling dataAdapter.Update(dataSet, "EMPLOYES"). The
xml file contains data for more thatn one table.
But my needs is to upate all Dataset tables.
What is the way for doing this ?

using( SqlConnection cnx = new SqlConnection(sCnx) ) {
using( SqlDataAdapter dataAdapter = new SqlDataAdapter() ) {
DataSet dataSet = new DataSet();
string sCmd = "SELECT * FROM EMPLOYEES";
dataAdapter.SelectCommand = new SqlCommand(sCmd, cnx);
SqlCommandBuilder cmdBuilder = new
SqlCommandBuilder(dataAdapter);
dataSet.ReadXml(@"C:\DataFile.xml");
dataAdapter.Update(dataSet, "EMPLOYES");
}
}

Sam
 
J

JIGNESH

DataAdaptor can update only Single table for which he has valid SQLin his
UpdateCommand,Insertcommend and DeleteCommand properties. Also it requires
mapping information which he builds internally looking at SelectCommand
property.

So if you XML file contains multiple table you need that many SQLDataAdaptors

Regards
JIGNESH.
 
C

Cor Ligthert[MVP]

Sam,

A SQL database (not the Microsoft one however every one) is based on a very
old verhicle. It is still based on processing punching cards (which got
latter a more sophisticated name records and now mostly called row).

Updating punching cards is inserting new ones, deleting records from the
file or do changes on it. Moreover SQL is based on selecting data and is
updating something the first inventors of SQL probably never thought about,
processing puch cards was: selecting, sorting, do some simple math and
printing; the other work was done by few not visible for the end user.

Therefore the database has to know if your record is new or is an update. (I
have seen in antoher newsgroup that you have got an answer like that but
there there was not this information from you)

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top