Dear sir/Madam,
In my codes CmdDisplay button display only first record from the table and button2 add the all name (Ename field) to combobox1 from the table. How can i show FirstRecord, PreviousRecord, NextRecord and LastRecord using OleDbCommand and OleDBdataReader. Please guide me.
Dim cn As OleDbConnection
Dim cmd As OleDbCommand
Dim dr As OleDbDataReader
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\emp.mdb;")
cn.Open()
End Sub
Private Sub CmdDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdDisplay.Click
cmd = New OleDbCommand("select * from table1", cn)
dr = cmd.ExecuteReader()
If dr.Read() = True Then
TextBox1.Text = dr("empno")
TextBox2.Text = dr("Ename")
TextBox3.Text = dr("Department")
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
cmd = New OleDbCommand("select * from table1", cn)
dr = cmd.ExecuteReader()
Do While dr.Read()
ComboBox1.Items.Add(dr("ename"))
Loop
End Sub