esposito Posted April 25, 2004 Posted April 25, 2004 Hello, I'm new to ASP.NET and I badly need your help. I have created an Access database (Customers.mdb) containing a table called Customers with three fields, namely Surname, FirstName and Phone. I have placed three textboxes in a Web form and a button to move to the next record. Now, the problem is, when I first click on the button I go straight to the second record. When I click again it moves regularly to the next record. Do you know how to modify the code below so that when I first click on btnNext I get the record with index=0, that is the first record in the database? Thanks in advance. The incriminated code runs as follows: Sub btnNext_Click(sender As Object, e As EventArgs) Try Dim MySQL as string = "Select * from Customers" Dim myConn As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & server.mappath("Customers.mdb") & ";") Dim ds as DataSet=New DataSet() Dim Cmd as New OleDbDataAdapter(MySQL,MyConn) Cmd.Fill(ds,"Customers") Dim RecordPos As Integer = CType(Session("RecordPos"), Integer) If RecordPos > ds.Tables("Customers").Rows.Count -2 Then RecordPos -= 1 End If RecordPos += 1 lblCurrentRecord.Text = (RecordPos + 1).ToString Session("RecordPos") = RecordPos txtSurname.Text = ds.Tables("Customers").Rows(RecordPos)("Surname").ToString txtFirstName.Text = ds.Tables("Customers").Rows(RecordPos)("FirstName").ToString txtPhone.Text = ds.Tables("Customers").Rows(RecordPos)("Phone").ToString MyConn.Close() Catch End Try End Sub Quote Pasquale Esposito Perugia - Italy http://www.geocities.com/espositosoftware
Moderators Robby Posted April 25, 2004 Moderators Posted April 25, 2004 Look into Currency Manager and Data Binding. Quote Visit...Bassic Software
georgepatotk Posted April 26, 2004 Posted April 26, 2004 Sub Form_Load(...) Dim MySQL as string = "Select * from Customers" Dim myConn As OleDbConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & server.mappath("Customers.mdb") & ";") Dim ds as DataSet=New DataSet() Dim Cmd as New OleDbDataAdapter(MySQL,MyConn) Cmd.Fill(ds,"Customers") End Sub Sub btnNext_Click(sender As Object, e As EventArgs) Dim RecordPos as Integer Me.BindingContext(ds, "Customer").Position = Me.BindingContext(ds, "Customer").Position + 1 RecordPos = Me.BindingContext(ds, "Customer").Position txtSurname.Text = ds.Tables("Customers").Rows(RecordPos)("Surname").ToString txtFirstName.Text = ds.Tables("Customers").Rows(RecordPos)("FirstName").ToString txtPhone.Text = ds.Tables("Customers").Rows(RecordPos)("Phone").ToString End Sub Quote George C.K. Low
esposito Posted April 26, 2004 Author Posted April 26, 2004 Thanks a lot for your help. Pasquale Esposito Perugia, Italy Quote Pasquale Esposito Perugia - Italy http://www.geocities.com/espositosoftware
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.