Question What is the coding for Next & Previous Button?

avi4ever

Member
Joined
Feb 27, 2009
Messages
7
Programming Experience
1-3
Plz someone help me. I want the coding for next and previous button and its given on my form. I want to fetch the records from my database and display it on my form.
 
You set up a counter to track your current row. Then use something like this:

VB.NET:
Me.<textbox name>.Text = <dataset name>.<table name>.Rows(<row counter variable>)("<field name>").ToString
 
Here's an example of first, last, previous, and next button clicks.

VB.NET:
	Private Sub uxFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
	Handles uxFirst.Click

		Me.EmployeeBindingSource.MoveFirst()

	End Sub

VB.NET:
	Private Sub uxPrev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
	Handles uxPrev.Click

		If Me.EmployeeBindingSource.Position > 0 Then
			Me.EmployeeBindingSource.MovePrevious()
		End If

	End Sub

VB.NET:
	Private Sub uxNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
	Handles uxNext.Click

		If Me.EmployeeBindingSource.Position < Me.EmployeeBindingSource.Count - 1 Then
			Me.EmployeeBindingSource.MoveNext()
		End If

	End Sub

VB.NET:
	Private Sub uxLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
	Handles uxLast.Click

		Me.EmployeeBindingSource.MoveLast()

	End Sub
 
You don't have to check the BindingSource.Position MattP, the Move.. methods calls this property and the setter adjusts it automatically.

In relation to this, if you are setting things up manually you can add a BindingNavigator to form from toolbox and assign it your BindingSource, the navigator will the connect to and use the source methods and properties automatically. Perhaps you can also read about using the wizards to setup the data access and form bindings for you.
 
Codin for to connect

Well i m using vb.net 2008 & my back-end is SQL Server 2005. I need it badly
Plz giv me the most easiest codin. Here is the design of my form1:
Label-FName Textbox1.Text
Label-LName Textbox2.Text

Button1-Next Button2-Previous
Button3-Update

After dis take two radio button one for "View" & another for "Edit". After dis the main problem comes i want to see the database details(fname, lname) in dis form1. And about the radio button the moment i'll select "View" radio button it should display the details(fname, lname) bt the textfield1 & 2 wil be disabled & when i'll click "Edit" radio button it should also display the details bt da textfields1 & 2 will be enabled so i can edit n "Update". And if u can give me the codings for database connection i'll be grateful to you. Thank You
 
Back
Top