Please could some1 help.
I have a OleDbConnection, to an access database (jet4) OleDbCommand then than Inserts a record - which works.
For each record a Autonumber primary key is created. Now what i want is for the newly created id to get brought back and showed on the form.?
Heres my code to insert.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'-----------------------------------------------
OleDbCommand1.Parameters("Name").Value = TextBox.Text
'-----------------------------------------------
Dim SQLreturn As Integer
'OPEN THE CONNECTION AND EXECUTE THE COMMAND
Try
OleDbConnection1.Open()
SQLreturn = OleDbCommand1.ExecuteNonQuery()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
'END - SHOW EX MESSAGE IF NEED BE
'-----------------------------------------------
'-----------------------------------------------
'TEST IF STUFF WENT IN
If SQLreturn <> 1 Then
MessageBox.Show("Could not execute the INSERT query", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
MessageBox.Show("Database Update Sucsesfull", "Confirm", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
OleDbConnection1.Close()
'END ME TEST - CLOSE THE CONNECTION
'-----------------------------------------------
End Sub