previous and next button

plumage

Active member
Joined
Jul 12, 2004
Messages
38
Programming Experience
Beginner
is there any other way to write the codes for buttons(next, and previous button to view record) if i dont have dataset?thanks
 
for txtbox, i use readonly to make the txtbox uneditable,then for button,how can i make it unpressable? anyone know?

btw the way,thank for the help..now trying to use datareader for the next button,but looks like it gives me problems too..

thanks.
 
i use the below code for the next button, but it wont work.iszit because my coding is all wrong?

below is my coding:

Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click

Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Documents and Settings\YangLim\My Documents\Assignment2.mdb"

Dim MyConn As New OleDbConnection(strConn)

Dim MySQL As String

MySQL = "SELECT CustomerID,CustomerName,CustomerAddress,CustomerPostCode,CustomerGender,CustomerContactNo,CustomerDOB,CustomerNRIC FROM Customer "

Dim cmd As New OleDbCommand(MySQL, MyConn)

MyConn.Open()

Dim reader As OleDbDataReader

reader = cmd.ExecuteReader

'read the first row

If reader.Read() Then

'set the textBoxs with appropriate data

txtCustID.Text = reader("CustomerID")

txtName.Text = reader("CustomerName")

txtAddress.Text = reader("CustomerAddress")

txtPostcode.Text = reader("CustomerPostCode")

cboGender.Text = reader("CustomerGender")

txtContactNo.Text = reader("CustomerContactNo")

txtDOB.Text = reader("CustomerDOB")

txtIC.Text = reader("CustomerNRIC")

Else

txtCustID.Text = ""

txtName.Text = ""

txtAddress.Text = ""

txtPostcode.Text = ""

cboGender.Text = ""

txtContactNo.Text = ""

txtDOB.Text = ""

txtIC.Text = "End Of file"

End If

reader.Close()

MyConn.Close()

End Sub

 
If your code is in the event handler of a button's click event, you will always get the first returned record.

What you should do is read the dataSource into a dataSet (or just dataTable), use dataBindings for the textBoxs, and then adjust the position of the BindingContext. This method will save you many trips to the dataSource.

Here is a link to some good articles regarding ADO.NET on the MSDN site: Using ADO.NET

If you are using Visual Studio, you can use the Data Form Wizard to create all the dataBindings; Next, Previous, First, and Last Record Buttons; Record count (Record X of Y); and Update, Cancel, and Load buttons.
 
i use the below code to navigate my record to next record but it give problem..
can anyone help me c where did i went wrong. or iszit my coding for my loading of data is wrong. cos for my loading of data, i use data reader to read from my database and load to my window form,it is wrong iszit because it only read the first data, that y i cant run my next button?


PHP:
Protected mybindingManagerBase As BindingManagerBase


PHP:
 Sub movenext() 
 
Try
 
mybindingManagerBase.Position += 1
 
Catch
 
unhandledexceptionHandler()
 
End Try
 
End Sub
PHP:
Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
 
Try 
 
movenext()
 
Catch
 
UnhandledExceptionHandler()
 
End Try
 
Last edited:
Back
Top