B
Benjamin
Hi!
I create a new row in dataset "ds" and press "save" where following is done:
ds = the full dataset, that was loaded at the start up of the form
dsChanges = that is simply ds.GetChanges(). this dataset is the one sent
down to "data layer"
Step 1.
'We can see that the new row is created - note the status "Added":
ds.tables("PriceLists").rows.count ---> 21 Integer
ds.Tables("PriceLists").Rows(20).Rowstate ---> Added
System.Data.DataRowState
'Note that I have not entered ID for PK column - that is automaticly
generated in "data layer":
ds.Tables("PriceLists").Rows(20).Item("PriceListID") {System.DBNull} Object
'We can also see that the "difference dataset" contains the new row:
dsChanges.Tables("PriceLists").Rows.Count ---> 1 Integer
'...and of course is the PK column still correctly null:
dschanges.tables("PriceLists").Rows(0).Item("PriceListID") {System.DBNull}
Object
Step 2.
'I send down dsChanges to data layer. The data layer returns a dsChanges
that update is done on (using stored procedures...).
'We can no see that the row has successfully been added to the database,
'with a "Identity" (MSSQL) value as PK. Perfect!:
dschanges.tables("PriceLists").Rows(0).Item("PriceListID") 1635 {Integer}
Object
Step 3.
'Let me now simply do a "ds.Merge(dsChanges)" and have a new look at the
values.
'What! - Merge has added a NEW row instead of updating the newly created
one.
ds.Tables("PriceLists").Rows.Count ---> 22 Integer
'The row that was added by me was not touched by the Merge (status still
"Added") - see:
ds.Tables("PriceLists").Rows(20).Rowstate ---> Added
System.Data.DataRowState
ds.Tables("PriceLists").Rows(20).Item("PriceListID") {System.DBNull} Object
'But the - NOT WANTED - new row that Merge created has the new PK value.
ds.Tables("PriceLists").Rows(21).Item("PriceListID") 1635 {Integer} Object
Merge fails to understand how to merge the newly created row that was
bounced to data layer and complemented with the "automaticly created unique
primary key value" (quote from help file above).
Can you understand my problem?
Working with the combination of "GetChanges" / "Merge" / "MSSQL - Identity
column" must be a common scenario.
The scenario should really work - MS is describing it in the help file
referred to above ;-)
I really hope I am doing something wrong - but what ?
Can it be the lack of .PrimaryKey constraint on the DataTable that makes it
impossible for Merge to find the row to update?
BUT I can NOT have a .PrimaryKey constraint - as I have understood - because
the client dataset MUST ALLOW the PriceListID column to be NULL until
complemented with "Identity generated PK" by data layer.
Coding in VisualBasic.
Best regards
Benjamin Tengelin, Sweden
I create a new row in dataset "ds" and press "save" where following is done:
ds = the full dataset, that was loaded at the start up of the form
dsChanges = that is simply ds.GetChanges(). this dataset is the one sent
down to "data layer"
Step 1.
'We can see that the new row is created - note the status "Added":
ds.tables("PriceLists").rows.count ---> 21 Integer
ds.Tables("PriceLists").Rows(20).Rowstate ---> Added
System.Data.DataRowState
'Note that I have not entered ID for PK column - that is automaticly
generated in "data layer":
ds.Tables("PriceLists").Rows(20).Item("PriceListID") {System.DBNull} Object
'We can also see that the "difference dataset" contains the new row:
dsChanges.Tables("PriceLists").Rows.Count ---> 1 Integer
'...and of course is the PK column still correctly null:
dschanges.tables("PriceLists").Rows(0).Item("PriceListID") {System.DBNull}
Object
Step 2.
'I send down dsChanges to data layer. The data layer returns a dsChanges
that update is done on (using stored procedures...).
'We can no see that the row has successfully been added to the database,
'with a "Identity" (MSSQL) value as PK. Perfect!:
dschanges.tables("PriceLists").Rows(0).Item("PriceListID") 1635 {Integer}
Object
Step 3.
'Let me now simply do a "ds.Merge(dsChanges)" and have a new look at the
values.
'What! - Merge has added a NEW row instead of updating the newly created
one.
ds.Tables("PriceLists").Rows.Count ---> 22 Integer
'The row that was added by me was not touched by the Merge (status still
"Added") - see:
ds.Tables("PriceLists").Rows(20).Rowstate ---> Added
System.Data.DataRowState
ds.Tables("PriceLists").Rows(20).Item("PriceListID") {System.DBNull} Object
'But the - NOT WANTED - new row that Merge created has the new PK value.
ds.Tables("PriceLists").Rows(21).Item("PriceListID") 1635 {Integer} Object
Merge fails to understand how to merge the newly created row that was
bounced to data layer and complemented with the "automaticly created unique
primary key value" (quote from help file above).
Can you understand my problem?
Working with the combination of "GetChanges" / "Merge" / "MSSQL - Identity
column" must be a common scenario.
The scenario should really work - MS is describing it in the help file
referred to above ;-)
I really hope I am doing something wrong - but what ?
Can it be the lack of .PrimaryKey constraint on the DataTable that makes it
impossible for Merge to find the row to update?
BUT I can NOT have a .PrimaryKey constraint - as I have understood - because
the client dataset MUST ALLOW the PriceListID column to be NULL until
complemented with "Identity generated PK" by data layer.
Coding in VisualBasic.
Best regards
Benjamin Tengelin, Sweden