29-10-18, 09:57 PM
أو يمكنك أن تجرب هذا الكود أسهل و أبسط من كل هذا :
كود :
Dim Dst = New DataSet
Dim OleCn As New OleDbConnection
Dim myDA As OleDbDataAdapter
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
SNoNavigation()
txtName.Focus()
Me.KeyPreview = True
Catch ex As Exception
MsgBox(ex.Message(), MsgBoxStyle.Critical, "خطأ")
End Try
End Sub
Private Sub SNoNavigation()
Try
OleCn.ConnectionString = "Provider=Microsoft.Jet.oledb.4.0; Data Source=" & My.Application.Info.DirectoryPath.ToString() & "\DATABASEDDF.mdb;Persist Security Info=False"
If OleCn.State = ConnectionState.Closed Then OleCn.Open()
myDA = New OleDbDataAdapter("Select IIF(Max(SerialNo) Is NULL,1,Max(SerialNo)+1) From Table1", OleCn)
myDA.Fill(Dst, "Table1")
txtSerialNo.Text = Dst.Tables("Table1").Rows(0)(0).ToString()
Catch ex As Exception
MsgBox(ex.Message(), MsgBoxStyle.Critical, "خطأ بالترقيم")
End Try
End Sub