get the record id after inserting

Joined
Mar 25, 2009
Messages
23
Programming Experience
Beginner
hello

I use this code to insert a record to a table
VB.NET:
CustodiesTableAdapter.InsertQuery(cname, Now.Date, 0, cnotes, eid)

the record contains an autonumber field (cid)

i need this value after inserting

I used this code
VB.NET:
CustodiesBindingSource.MoveLast()
Dim cid As Long = CLng(DirectCast(CustodiesBindingSource.Current, DataRowView)("cid"))

but it returns the id of the last record before adding the new one

how to get the right value

Regards
 
If the parameter was declared as inputoutput or output then you'd have to pass it ByRef and it would contain the calcualted value when Insertuery finishes... But tyically you wouldnt use this, you'd just use a dataset and tableadapter configured to "refresh the dataset" (advanced options)
 
Back
Top