Public Class Form1
Dim dbProvider As String
Dim dbSource As String
Dim con As New OleDb.OleDbConnection
Dim sql As String = "SELECT * FORM tb1"
Dim ds As New DataSet
Dim da As OleDb.OleDbDataAdapter
Dim i As Integer
Dim len As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Load
dbProvider = "PROVIDER=Microsoft.jet.OLEDB.4.0;"
dbSource = "Data Source = C:\student.mdb"
con.ConnectionString = dbProvider & dbSource
con.Open()
da = New OleDb.OleDbDataAdapter(sql, con)
da.Fill(ds, "student")
len = da.Fill(ds, "student")
End Sub
Private Sub nav()
TextBox1.Text = ds.Tables("tb1").Rows(i).Item(1)
TextBox2.Text = ds.Tables("tb1").Rows(i).Item(2)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
i = 0
nav()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If (i = 0) Then
MsgBox("This is First")
Else
i = i - 1
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If (i = len - 1) Then
MsgBox("This is Last")
Else
i = i + 1
End If
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
i = len - 1
nav()
End Sub
End Class
แต่ก็ยังติด Error
Code (VB.NET)
Private Sub nav()
TextBox1.Text = ds.Tables("tb1").Rows(i).Item(1)
TextBox2.Text = ds.Tables("tb1").Rows(i).Item(2)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim conn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\student.mdb")
Dim Cat As New OleDb.OleDbDataAdapter("Select * from tb1", conn)
Dim Emplo As New OleDb.OleDbDataAdapter("Select id,code,name", conn)
Cat.Fill(Dset, "Showcat")
Emplo.Fill(Dset, "ShowEmplo")
End Sub
Code (VB.NET)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
DataGridView1.DataSource = Dset.Tables("ShowCat")
End Sub