Hi i have read loads of other threads. But none solved this problem.
I want to return the correct identity after a bindingsource.addnew command.
So i do a tableapdater.update.
It always returns 0! after the update call.
Maybe the connection.closes.
I use this inline in a function called New Estimate.
Private Function EstimateNoNewID() As Integer Dim newId As Integer = 0 Dim idCMD As New OleDb.OleDbCommand("SELECT @@IDENTITY FROM Estimates", EstimatesTableAdapter.Connection)newId =
CInt(idCMD.ExecuteScalar())EstimatesTableAdapter.Connection.Close()
Return newId 'identity retrieved and stored End Functioni also tried it inline on the estimates datatable, but had difficulties getting a reference to a connection. So i gave up! and put the function at form level
Partial Class EstimatesDataTable
Private Sub EstimatesDataTable_EstimatesRowChanged(ByVal sender As Object, ByVal e As EstimatesRowChangeEvent) Handles Me.EstimatesRowChanged
'pseudo code
if Action = row.added then
Dim newId As Integer = 0
Dim idCMD As New OleDb.OleDbCommand("SELECT @@IDENTITY FROM Estimates", Connection)
newId = CInt(idCMD.ExecuteScalar())
row("Estimate No") = newID
end if
End Sub'Could not get a connection!!!
i tried datadatasetTableadapters.EstimatesTableAdapter.Connection, There was some problem with shared and references etc. Couldnt work it out!
When viewing the dataDataset, estimates table in dataDataset.xsd, click configure, advanced, the option for refresh is disabled and not checked. Also i am not getting default values, so i have to code them in too!
Any solutiuon will be great as ebough pulled hair out. I will have to drop all keys, put in an idcounter table and recode all forms for insert!!!!!
The application i have written really rocks, this is the only bit left!! please help!

Problem using @@IDENTITY when connecting to Access XP HELP project deadline looming! VB.Net Visual Studio 2005
Phil Spokas
You should do an insert, and directly call @@identity after it, or , at least, call @@identity in the same db - session (so , using the same connection)
eddy1421
witkamp
The wining code at form level was:
Me.EstimatesBindingSource.AddNew()row =
CType(CType(Me.EstimatesBindingSource.Current, DataRowView).Row, dataDataSet.EstimatesRow) row._Date = Date.Today.ToShortDateStringrow.Subject = JobDescription
row.Path =
"<<new>>"EstimatesBindingSource.EndEdit()
EstimatesTableAdapter.Connection.Open()
EstimatesTableAdapter.Update(DataDataSet.Estimates)
Dim newId As Integer = 0 Dim idCMD As New OleDb.OleDbCommand("SELECT @@IDENTITY FROM Estimates", EstimatesTableAdapter.Connection)newId =
CInt(idCMD.ExecuteScalar())EstimatesTableAdapter.Connection.Close()
MessageBox.Show(newId)