J
John
Hi
I am using below vb.net code to insert a record into an access table and
then retrieve the auto number id using @@Identity;
If LocalConn.State = ConnectionState.Closed Then
LocalConn.Open()
End If
Dim DBCommand As System.Data.OleDb.OleDbCommand
Dim I As Integer
St = "INSERT INTO tblClients ( TempID ) SELECT 123 "
DBCommand = New System.Data.OleDb.OleDbCommand(St, LocalConn)
I = DBCommand.ExecuteNonQuery()
Dim Cmd As OleDb.OleDbCommand
Dim Reader As OleDb.OleDbDataReader
Dim ID As Int32
St = "SELECT @@Identity as ID"
Cmd = New OleDb.OleDbCommand(St, LocalConn)
Reader = Cmd.ExecuteReader()
If (Reader.Read()) Then
ID = CInt(Reader.GetValue(Reader.GetOrdinal("ID")))
End If
The problem is that ID returns a 0 (zero) value instead of the actual id
value. What am I doing wrong?
Many Thanks
Regards
I am using below vb.net code to insert a record into an access table and
then retrieve the auto number id using @@Identity;
If LocalConn.State = ConnectionState.Closed Then
LocalConn.Open()
End If
Dim DBCommand As System.Data.OleDb.OleDbCommand
Dim I As Integer
St = "INSERT INTO tblClients ( TempID ) SELECT 123 "
DBCommand = New System.Data.OleDb.OleDbCommand(St, LocalConn)
I = DBCommand.ExecuteNonQuery()
Dim Cmd As OleDb.OleDbCommand
Dim Reader As OleDb.OleDbDataReader
Dim ID As Int32
St = "SELECT @@Identity as ID"
Cmd = New OleDb.OleDbCommand(St, LocalConn)
Reader = Cmd.ExecuteReader()
If (Reader.Read()) Then
ID = CInt(Reader.GetValue(Reader.GetOrdinal("ID")))
End If
The problem is that ID returns a 0 (zero) value instead of the actual id
value. What am I doing wrong?
Many Thanks
Regards