Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Pasquale Esposito

Perugia - Italy

http://www.geocities.com/espositosoftware

Posted
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

George C.K. Low

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...