elementary ADO.Net question

MarkD

Active member
Joined
Mar 27, 2003
Messages
31
Location
Burlington, VT, USA
Happy Memorial Day! :)

I have an ADO.Net datatable coding question; this may be elementary, but Im stumped...

Is there an easy way (or whats the best way) to retrieve the key of a record you just added to a table? I have the following code... can someone help me fill in the ???

add a new row to the table
Dim drRow As DataRow
drRow = selectedDataTbl.NewRow()
selectedDataTbl.Rows.Add(drRow)

save its ID
iCurrentRowID = selectedDataTbl.???

Thanks,
Mark
 
If you mean that the row has a primary key field, autonumbering ID field or similar then the current version of drRow will provide access to the populated field.
 
Thanks Afraits,

Yes, it is an autonumber field. Do you have an example line of code I would use to do this?

(I tried:

iCurrentRow = drRow.Item("IncidentID")

after the .Add(drRow) above thinking by that time the key would have been assigned in the datatable but it comes back NULL)
 
The ID column in your datatable needs to have its autoincrement property set to true, the autoincrementseed and autoincrementstep needs to be set aswell, this way it will autogenerate a value when a new row is entered.
 
Back
Top