J
Jim Rand
The dataAdapter insert sql:
INSERT INTO Customer (CustomerOldID, CompanyName, ContactName, ContactTitle, Address, City, Region, PostalCode, Country, Phone, Fax) VALUES (@CustomerOldID, @CompanyName, @ContactName, @ContactTitle, @Address, @City, @Region, @PostalCode, @Country, @Phone, @Fax); SELECT CustomerID, CAST(TS AS INT) AS TS FROM Customer WHERE (CustomerID = @@IDENTITY)
AutoIncrement: true
AutoIncrementSeed: -1
AutoIncrementStep: -1
This code results in duplicate rows appearing in the dataset after an insert:
DataSet dsChanges = dsNorthwind.GetChanges(); // Gets the row inserted
sqlDACustomer.Update(dsChanges, "Customer"); // Backend gets updated
dsNorthwind.Merge(dsChanges); // Both original inserted row with a CustomerID = -1 still exists and new real row
// with CustomerID = 104 appears resulting in two rows appearing in the grid
dsNorthwind.AcceptChanges();
------------------------------------------------------------------------------------------------
This code works:
sqlDACustomer.Update(dsNorthwind, "Customer"); // Backend gets updated
dsNorthwind.AcceptChanges(); // grid has only 1 row with the correct autoincrement key and timestamp.
--------------------------------------------------------------------------------------------------
dsNorthwind.WriteXml(@"C:\Tmp\fulldataset.xml",XmlWriteMode.DiffGram);
writes out <Customer diffgr:id="Customer93" msdata:rowOrder="91"....
dsChanges.WriteXml(@"C:\Tmp\changes.xml",XmlWriteMode.DiffGram);
writes out <Customer diffgr:id="Customer1" msdata:rowOrder="0"
--------------------------------------------------------------------------------------------------------
Deletes and updates work just fine. I'm only having problems with the inserts.
How do you use the GetChanges() method for inserts and have the autoincrement keys and timestamps make there way back to the dataset to the correct row?
Do I have to build some kind of a hash table and manually update the primary key and timestamp in the dataset?
What is the best approach?
Thanks.
INSERT INTO Customer (CustomerOldID, CompanyName, ContactName, ContactTitle, Address, City, Region, PostalCode, Country, Phone, Fax) VALUES (@CustomerOldID, @CompanyName, @ContactName, @ContactTitle, @Address, @City, @Region, @PostalCode, @Country, @Phone, @Fax); SELECT CustomerID, CAST(TS AS INT) AS TS FROM Customer WHERE (CustomerID = @@IDENTITY)
AutoIncrement: true
AutoIncrementSeed: -1
AutoIncrementStep: -1
This code results in duplicate rows appearing in the dataset after an insert:
DataSet dsChanges = dsNorthwind.GetChanges(); // Gets the row inserted
sqlDACustomer.Update(dsChanges, "Customer"); // Backend gets updated
dsNorthwind.Merge(dsChanges); // Both original inserted row with a CustomerID = -1 still exists and new real row
// with CustomerID = 104 appears resulting in two rows appearing in the grid
dsNorthwind.AcceptChanges();
------------------------------------------------------------------------------------------------
This code works:
sqlDACustomer.Update(dsNorthwind, "Customer"); // Backend gets updated
dsNorthwind.AcceptChanges(); // grid has only 1 row with the correct autoincrement key and timestamp.
--------------------------------------------------------------------------------------------------
dsNorthwind.WriteXml(@"C:\Tmp\fulldataset.xml",XmlWriteMode.DiffGram);
writes out <Customer diffgr:id="Customer93" msdata:rowOrder="91"....
dsChanges.WriteXml(@"C:\Tmp\changes.xml",XmlWriteMode.DiffGram);
writes out <Customer diffgr:id="Customer1" msdata:rowOrder="0"
--------------------------------------------------------------------------------------------------------
Deletes and updates work just fine. I'm only having problems with the inserts.
How do you use the GetChanges() method for inserts and have the autoincrement keys and timestamps make there way back to the dataset to the correct row?
Do I have to build some kind of a hash table and manually update the primary key and timestamp in the dataset?
What is the best approach?
Thanks.