Dear Developers

I have following codes on lostfocus of textbox1.text to search values.
It works fine but how to navigate database. I mean what codes should I use for Next Record and Previous Record Buttons.
My SQL database name is accounts and table name is employees

Please help

str = "select * from employees where sno =" & Val(Me.TextBox1.Text)
dt = GetTable(str)

If (dt.Rows.Count >= 1) Then
Me.TextBox2.Text = dt.Rows(0)("name")
Me.TextBox3.Text = dt.Rows(0)("city")
Me.TextBox4.Text = dt.Rows(0)("phone")
Else
Me.TextBox2.Text = ""
Me.TextBox3.Text = ""
Me.TextBox4.Text = ""
End If

'this function is in main module
Public Function GetTable(ByVal mstr As String)
cmd = New SqlClient.SqlCommand(mstr, con)
da = New SqlClient.SqlDataAdapter(cmd)
dt = New DataTable
da.Fill(dt)
Return (dt)
End Function

hi
declare a variable integer
dim i as integer 'a globle variable
within the next button sub :
If (dt.Rows.Count >= 1)
i+=1
if i <dt.Rows.Count
Me.TextBox2.Text = dt.Rows(i)("name")
Me.TextBox3.Text = dt.Rows(i)("city")
Me.TextBox4.Text = dt.Rows(i)("phone")
Else
i=0
end if
else
msgbox("database is empty")
end if

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.