Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Happy Memorial Day! :)

 

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

 

Is there an easy way (or what's 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

Posted
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.

Afraits

"The avalanche has started, it is too late for the pebbles to vote"

Posted

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)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...