D
Dana King
I primarily work with SQL (thank god) so I have an Access question. Thanks
in advance for some insight.
I am trying to insert a new record and have the identity returned. I have
been using the code below but no luck. It always returns 0
As you can see I'm trying to return it on the same open connection. I've
tried various other things but no luck either.
working with ADO.net 2.0
Dim newID As String = String.Empty
Dim cn As New
OleDbConnection(ConfigurationManager.ConnectionStrings("ArticlesConnection").ToString)
Dim cmd As New OleDbCommand(sql.ToString, cn)
cmd.CommandType = Data.CommandType.Text
cn.Open()
cmd.ExecuteNonQuery()
cmd.CommandText = "SELECT @@IDENTITY" '== DOES NOT WORK
cmd.CommandType = Data.CommandType.Text
cmd.Connection = cn
newID = cmd.ExecuteScalar.ToString
cn.Close()
in advance for some insight.
I am trying to insert a new record and have the identity returned. I have
been using the code below but no luck. It always returns 0
As you can see I'm trying to return it on the same open connection. I've
tried various other things but no luck either.
working with ADO.net 2.0
Dim newID As String = String.Empty
Dim cn As New
OleDbConnection(ConfigurationManager.ConnectionStrings("ArticlesConnection").ToString)
Dim cmd As New OleDbCommand(sql.ToString, cn)
cmd.CommandType = Data.CommandType.Text
cn.Open()
cmd.ExecuteNonQuery()
cmd.CommandText = "SELECT @@IDENTITY" '== DOES NOT WORK
cmd.CommandType = Data.CommandType.Text
cmd.Connection = cn
newID = cmd.ExecuteScalar.ToString
cn.Close()