C
christing
Guest
I face one issue is when my program set auto count id. my id can not auto cunt to next number. is i missing something.
Private Sub getNextNumber()
If Not app.State = ConnectionState.Open Then
'open connection
app.Open()
End If
Dim da As New OleDb.OleDbDataAdapter("select top 1 ID from ADMIN order by ID desc;", app)
Dim dt As New DataTable
'fill data to datatable
da.Fill(dt)
app.Close()
If dt.Rows.Count > 0 Then
txtID.Text = (Val(dt.Rows(0)(0)) + 1).ToString.PadLeft(10, "A")
Else
txtID.Text = "1".PadLeft(10, "A")
End If
End Sub
Private Function getLastNumber() As Integer
Dim app1 As New OleDb.OleDbConnection
app1.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=MYX.accdb"
If Not app1.State = ConnectionState.Open Then
app1.Open()
End If
Dim da As New OleDb.OleDbDataAdapter("select top 1 ID from ADMIN order by ID desc;", app1)
'desc = sort the data returned in descending order
Dim dt As New DataTable
da.Fill(dt)
app1.Close()
If dt.Rows.Count > 0 Then
Return Val(dt.Rows(0)(0))
End If
Return 0
End Function
Continue reading...
Private Sub getNextNumber()
If Not app.State = ConnectionState.Open Then
'open connection
app.Open()
End If
Dim da As New OleDb.OleDbDataAdapter("select top 1 ID from ADMIN order by ID desc;", app)
Dim dt As New DataTable
'fill data to datatable
da.Fill(dt)
app.Close()
If dt.Rows.Count > 0 Then
txtID.Text = (Val(dt.Rows(0)(0)) + 1).ToString.PadLeft(10, "A")
Else
txtID.Text = "1".PadLeft(10, "A")
End If
End Sub
Private Function getLastNumber() As Integer
Dim app1 As New OleDb.OleDbConnection
app1.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=MYX.accdb"
If Not app1.State = ConnectionState.Open Then
app1.Open()
End If
Dim da As New OleDb.OleDbDataAdapter("select top 1 ID from ADMIN order by ID desc;", app1)
'desc = sort the data returned in descending order
Dim dt As New DataTable
da.Fill(dt)
app1.Close()
If dt.Rows.Count > 0 Then
Return Val(dt.Rows(0)(0))
End If
Return 0
End Function
Continue reading...