Murray Brown
asked on
VB.net check the AutoIncrement property in an Access database
Hi
What VB.net code would I use to get the auto increment value of a column in
an Access database?
What VB.net code would I use to get the auto increment value of a column in
an Access database?
ASKER
Hi
Thanks.
If I have a table called "Transactions", how would I use your code to check the if the AutoIncrement value of the ID column?
Would I use SELECT @@IDENTITY FROM Transactions
or do I actually have to execute insert statement in order to get the value
Thanks.
If I have a table called "Transactions", how would I use your code to check the if the AutoIncrement value of the ID column?
Would I use SELECT @@IDENTITY FROM Transactions
or do I actually have to execute insert statement in order to get the value
for specific table use this:
Dim cmd As OleDbCommand = New OleDbCommand("SELECT IDENT_CURRENT('Transactions')+1", connection)
Dim reader As OleDbDataReader = cmd.ExecuteReader()
reader.Read()
dim nextIdentity as int = reader.Item(0).ToString()
ASKER
Hi. Thanks
I get the error "Undefined function ‘IDENT_CURRENT’ in expression"
when running the following code:
Dim cs As String = Globals.ThisAddIn.oRIGHT.l blConnecti onString.T ext
Dim myConnection As OleDbConnection = New OleDbConnection(cs)
Try
Dim cmd As OleDbCommand = New OleDbCommand("SELECT IDENT_CURRENT('" & oTableName & "')+1", myConnection)
myConnection.Open()
Dim reader As OleDbDataReader = cmd.ExecuteReader()
reader.Read()
Dim nextIdentity As Integer = reader.Item(0).ToString()
Is_Identity_Column = True
Catch ex As Exception
Is_Identity_Column = False
MsgBox(ex.Message)
End Try
I get the error "Undefined function ‘IDENT_CURRENT’ in expression"
when running the following code:
Dim cs As String = Globals.ThisAddIn.oRIGHT.l
Dim myConnection As OleDbConnection = New OleDbConnection(cs)
Try
Dim cmd As OleDbCommand = New OleDbCommand("SELECT IDENT_CURRENT('" & oTableName & "')+1", myConnection)
myConnection.Open()
Dim reader As OleDbDataReader = cmd.ExecuteReader()
reader.Read()
Dim nextIdentity As Integer = reader.Item(0).ToString()
Is_Identity_Column = True
Catch ex As Exception
Is_Identity_Column = False
MsgBox(ex.Message)
End Try
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi Sedgwick
The purpose of this code is to check if the ID column in table is an AutoIncrement field
I should have mentioned that in the question, but I thought that it was apparent in my code
The purpose of this code is to check if the ID column in table is an AutoIncrement field
I should have mentioned that in the question, but I thought that it was apparent in my code
the code i've posted will return u the next auto increment identity.
i'm not sure i'm following you
i'm not sure i'm following you
ASKER
Thanks very much
Open in new window