G
Guest
Hi Guys
I created a DataRow, that automatically sets its primary key. Let us say 3.
I then added the DataRow to the DataSet and then update the DataSet using
GetChanges() and finally Merge().
The primary key in the Microsoft SQL DB is set to 23 and consequently the PK
in the dataset's row is also set to 23.
What confuses me is that my originally created DataRow does still contain
the old PK value and therefore gives me some troubles.
I thought, that a the DataRow is passed as reference object and should
therefore be the same as the row in the dataset.
Is there any possibility to update this datarow without just getting the
last row from the updated dataset.
Appended the code that I use: ( the dataTable contains two columns, the PK
which is indexed and the name)
DataRow dr = myDataSet.MyTable.NewRow();
dr["Name"] = "Chris"; [dr["ID"] is set to 3!!!]
myDataSet.MyTable.Add(dr);
DataSet changedRecords = myDataSet.GetChanges();
myDataAdapter.Update(changedRecords);
myDataSet.Merge(changedRecords);
myDataSet.AcceptChanges(); [I am not sure if it needs this!]
myDataSet.MyTable.Rows[0]["ID"] is now 23!!!
dr["ID"] is still 3!!!!
Thanks for your help
Chris
I created a DataRow, that automatically sets its primary key. Let us say 3.
I then added the DataRow to the DataSet and then update the DataSet using
GetChanges() and finally Merge().
The primary key in the Microsoft SQL DB is set to 23 and consequently the PK
in the dataset's row is also set to 23.
What confuses me is that my originally created DataRow does still contain
the old PK value and therefore gives me some troubles.
I thought, that a the DataRow is passed as reference object and should
therefore be the same as the row in the dataset.
Is there any possibility to update this datarow without just getting the
last row from the updated dataset.
Appended the code that I use: ( the dataTable contains two columns, the PK
which is indexed and the name)
DataRow dr = myDataSet.MyTable.NewRow();
dr["Name"] = "Chris"; [dr["ID"] is set to 3!!!]
myDataSet.MyTable.Add(dr);
DataSet changedRecords = myDataSet.GetChanges();
myDataAdapter.Update(changedRecords);
myDataSet.Merge(changedRecords);
myDataSet.AcceptChanges(); [I am not sure if it needs this!]
myDataSet.MyTable.Rows[0]["ID"] is now 23!!!
dr["ID"] is still 3!!!!
Thanks for your help
Chris