Get identity or autonumber after Insert Query
Example Code for creating invoice
Private Sub CreateInvoiceQuery() Dim InsertCom = Me.InvoiceDataAdapterX.Adapter.InsertCommand If invoice_id = Nothing Then InsertCom.CommandText = "INSERT INTO `invoice` (`date_created`, `customerid`) VALUES (?, ?)" InsertCom.Parameters(0).Value = CType(Me.DateTimePicker1.Value, Date) InsertCom.Parameters(1).Value = 1 InsertCom.Connection.Open() InsertCom.ExecuteNonQuery() InsertCom.CommandText = "SELECT @@IDENTITY" invoice_id = InsertCom.ExecuteScalar NoInvoiceTextBox.Text = invoice_id.ToString("D6") InsertCom.Connection.Close() InsertCom.Dispose() End If Debug.WriteLine(invoice_id.ToString) End Sub
0 comments :
Post a Comment