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 

No comments :

Post a Comment

Related Posts Plugin for WordPress, Blogger...
 

Recent Posts

ping busuk

Pingje

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