AHHH! Different question and MUCH BETTER question!
GOOD!
It's simple: You just do another query:
using the *SAME OPEN CONNECTION*!!!
This is important! Many of the VS auto-generated controls will open the connection, make a query, and close the connection. You MUST prevent this. Make sure you are using the same open connection.
So if you create the code yourself, it's very easy. And you don't even need an OleDbReader; you can just use ExecuteScalar on the OleDbCommand object.
So your code sequence might be something like:
Code:
...
Dim SQL As String = "INSERT INTO table ..." ' wherever you get your SQL from
Dim conn As New OleDbConnection(...your connection string...)
conn.Open()
Dim cmd As New OleDbCommand( SQL, conn)
cmd.ExecuteNonQuery()
cmd.Dispose()
' you can reuse the cmd variable this way or use a different one:
cmd = New OleDbCommand( "SELECT @@IDENTITY", conn )
Dim newID As Integer = CINT( cmd.ExecuteScalar() )
cmd.Dispose()
conn.Close() ' NOW it is okay to close connection!
...