Deepak Andre

Deepak Andre

  • NA
  • 43
  • 3.3k

Auto increment with access database

Oct 26 2017 1:34 PM
Hello everyone,
 
I am new in vb.net and access database please need ur guideline, 
 
I am using vb.net 2010 and for database Microsoft access DB, 
 
my question is how can i set autoincrement on MemoNo
 
following code using and 
 
Imports System.Data.OleDb
Imports System.Drawing.Printing
Public Class Frmhire
Dim provider As String
Dim dataFile As String
Dim connString As String
Dim myConnection As OleDbConnection = New OleDbConnection
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSave.Click
provider = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source ="
'Change the following to your access database location
dataFile = "d:\testsoft\Projects\db\pankajdb.accdb"
connString = provider & dataFile
myConnection.ConnectionString = connString
myConnection.Open()
Dim str As String
str = "insert into HireSlip ([MemoNo], [Date],[Ms],[Truckno],[LodingDate],[Station],[Weight],[Detection],[Overload],[Freight],[Advance],[Balance],[Hamali],[Topay],[Refund],[Total]) values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
Dim cmd As OleDbCommand = New OleDbCommand(str, myConnection)
cmd.Parameters.Add(New OleDbParameter("MemoNo", CType(TxtMemo.Text, String)))
cmd.Parameters.Add(New OleDbParameter("Date", CType(DateOne.Text, String)))
cmd.Parameters.Add(New OleDbParameter("Ms", CType(TxtMs.Text, String)))
cmd.Parameters.Add(New OleDbParameter("Truckno", CType(TxtTruck.Text, String)))
cmd.Parameters.Add(New OleDbParameter("LodingDate", CType(DateTwo.Text, String)))
cmd.Parameters.Add(New OleDbParameter("Station", CType(TxtStation.Text, String)))
cmd.Parameters.Add(New OleDbParameter("Weight", CType(Txtweight.Text, String)))
cmd.Parameters.Add(New OleDbParameter("Detection", CType(TxtDetection.Text, String)))
cmd.Parameters.Add(New OleDbParameter("Overload", CType(TxtOverload.Text, String)))
cmd.Parameters.Add(New OleDbParameter("Freight", CType(TxtFreight.Text, String)))
cmd.Parameters.Add(New OleDbParameter("Advance", CType(TxtAdvance.Text, String)))
cmd.Parameters.Add(New OleDbParameter("Balance", CType(TxtBalance.Text, String)))
cmd.Parameters.Add(New OleDbParameter("Hamali", CType(TxtHamali.Text, String)))
cmd.Parameters.Add(New OleDbParameter("Topay", CType(TxtTopay.Text, String)))
cmd.Parameters.Add(New OleDbParameter("Refund", CType(TxtRefund.Text, String)))
cmd.Parameters.Add(New OleDbParameter("Total", CType(TxtTotal.Text, String)))
Try
cmd.ExecuteNonQuery()
cmd.Dispose()
myConnection.Close()
TxtMemo.Clear()
DateOne.Clear()
TxtMs.Clear()
TxtTruck.Clear()
DateTwo.Clear()
TxtStation.Clear()
Txtweight.Clear()
TxtDetection.Clear()
TxtOverload.Clear()
TxtFreight.Clear()
TxtAdvance.Clear()
TxtBalance.Clear()
TxtHamali.Clear()
TxtTopay.Clear()
TxtRefund.Clear()
TxtTotal.Clear()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub Frmhire_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim thedate As Date
thedate = Format(Now(), "short date")
DateOne.Text = thedate
DateTwo.Text = thedate
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Close()
End Sub
End Class

Answers (8)