sqlDataAdapter.Update using Dataset.Merge -- Does not work -- any reason?

G

geeksgk

Gurus,

Here is what I'm trying to do.

I have a table in sql server. The data for this table comes from a XML
(with matching schema) from an external system. I'm trying to read the
xml into a dataset and then use the sqlDataAdapter.update command to
insert the data into the table.

Here is my source dode and IT DOES NOT INSERT ANY RECORDS AND IT DOES
NOT GIVE ANY ERROR TOO. PLS HELP

string strConnectionString = "conection string goes here";

string SelectQuery = "SELECT PicklistID, PicklistCode, PicklistDesc
FROM temp123";
SqlDataAdapter myDataAdapter = new SqlDataAdapter();
SqlConnection mySQLConnection = new SqlConnection(strConnectionString);
SqlCommand mySQLSelectCommand = new SqlCommand(SelectQuery,
mySQLConnection);
myDataAdapter.SelectCommand = mySQLSelectCommand;
SqlCommandBuilder cmdb = new SqlCommandBuilder(myDataAdapter);

DataSet myDataSet = new DataSet();

myDataAdapter.Fill(myDataSet);

DataSet NewDataSet = new DataSet();

NewDataSet.ReadXmlSchema("myXmlDocumentSchema.xsd");
NewDataSet.ReadXml("myXmlDocument.xml");

myDataSet.Merge(NewDataSet, true);

myDataAdapter.Update(myDataSet);


What baffles me is that when I run this code IT DOES NOT GIVE ANY ERROR
and also it DOES NOT insert/update or delete any record in the
database.

myXmlDocument.xml has data and it matches the schema of the table.
What's wrong?
 
R

Ritesh Jain via DotNetMonster.com

Hi,
There is nothing wrong with ur code .........just u missed out one thing Assign the InserCommand of ur sqlAdapter myDataAdapter

i.e
myDataAdapter.InsertCommand = SQLInsertCOmmandObject

I hope this will solve ur Problem

Regards,
Ritesh
 

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