0

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

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by wiss.dev
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.