views:

111

answers:

2

Say that I have this code:

rentalEaseDataSet.tblCheckbookEntry.Rows.Add(newRow);

I want to get the identity of a column from that row I just added. How can I do this? Say the row is called ID.

For reference, I'm using C# and sql server express.

+3  A: 

Well, that row hasn't actually been saved to the database yet, so it doesn't have a database id (so sql server express isn't an issue). You need to use the adapter to save the changes, and then the id of newRow should reflect the database.

Marc Gravell
So newRow will automagically update itself?
Malfist
The adapter assumes responsibility for changes in both directions, yes.
Marc Gravell
+2  A: 

Assuming you are dealing with an auto-incremented identity value on the source of the data, you can't do this. You have to commit the changes to the data source through a data adapter, and then the column that represents the auto incremented id will be updated with the value.

casperOne