Tuesday, 16 July 2013

VB.NET Get Identity After Insert Query

Get the identify or auto number after insert query from ms access database
Example Coding for creating new invoice
  Private Sub CreateInvoiceQuery()
        Dim InsertCom = Me.InvoiceDataAdapterX.Adapter.InsertCommand
       
            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()
      
        Debug.WriteLine(invoice_id.ToString)
    End Sub 
 

Recent Posts

ping busuk

Pingje

There was an error in this gadget

Google+ Followers

HarryD Blog © 2013. All Rights Reserved | Back To Top