I need to update my database based on an xml stream sent to asp.net from another application. this is how it works:
1. asp.net generates a dataset and sends the xml to a seperate director application (dataset.GetXml())
2. director app modifies xml, then sends it back to asp.net.
3. asp.net reads xml into a new dataset, then needs to update the database.
this is what i'm doing for step 3:
SqlConnection cn = Global.GetConnection();
// provide the adapter with a select so the sqlcommandbuilder can do everything else
SqlDataAdapter ada = new SqlDataAdapter("SELECT * FROM Customers", cn);
SqlCommandBuilder builder = new SqlCommandBuilder(ada);
// load in the xml that was sent from director application, along with the Schema
DataSet dsTemp = new DataSet();
// save changes to database
I get this error:
Violation of PRIMARY KEY constraint 'aaaaacustomers_PK'. Cannot insert duplicate key in object 'customers'. The statement has been terminated.
It's obvious that when i call ada.Update, it's trying to do an Insert. How do I make it do an update instead? the dataset only contains one table, CustomerInformation which only contains one row. The RowState of that row is "Added" when it needs to be "Modified" in order to work.
please advise :)