Connecting Tech Pros Worldwide Forums | Help | Site Map

Next/Previous Record

Member
 
Join Date: Jul 2009
Posts: 41
#1: Jul 27 '09
Hello again, and happy monday!

Well I'm getting better with this and learning a lot. I've come to another road block. I'm trying to figure out a way to "scroll" through records in my Access table, one by one. It's a little different than recordsets, it seems.

Here's the code I used to guess how it might work... and it doesn't lol.

I'm guessing I'm not loading the datatable correctly, but any help would be appreciated as always :)

Jesse

Expand|Select|Wrap|Line Numbers
  1. Protected Sub NextBN_Click(ByVal sender As Object, ByVal e As EventArgs) Handles NextBN.Click
  2.         Dim cn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\WebRMS_Mobile\WebRMS.mdb")
  3.         Dim dbcomm As New OleDbCommand("SELECT PageURL FROM ArmyRootURLPages", cn)
  4.         Dim dr As OleDbDataReader
  5.         Try
  6.             cn.Open()
  7.             dr = dbcomm.ExecuteReader
  8.             Dim dt As New DataTable("ArmyRootURLPages")
  9.             dt.Load(dr)
  10.             If dr.HasRows() Then
  11.                 While (dr.Read)
  12.                     PageURL.Text = dr("PageURL")
  13.                 End While
  14.             End If
  15.         Catch ex As Exception
  16.             MsgBox(ex.Message)
  17.         Finally
  18.             cn.Close()
  19.         End Try
  20.  
  21.  
  22.     End Sub

Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,137
#2: Jul 27 '09

re: Next/Previous Record


I'm really not sure what you're trying to do??

You have an Access Database and you want to display records to the end user.
I see that you're filling a table (manually) with each record from the Access Database but don't see any indication of what control you're using to display the records.

What are you trying to do?
What controls are you using?
Are you sure you want to "scroll" through the records? Do you maybe want to "page" through them (with next/previous buttons)?



-Frinny
ThatThatGuy's Avatar
Member
 
Join Date: Jul 2009
Location: Mumbai--India
Posts: 44
#3: Jul 30 '09

re: Next/Previous Record


Dim cn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\WebRMS_Mobile\WebRMS.mdb");

The reference to the MDB file is incorrect...when you're developing any web application...the path to it's resources should reside inside the project directory....
In this case.... you could have used something like this....
Dim cn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=Server.MapPath("App_Data\\WebRMS.mdb");

Usually the database files are inside App_Data folder which is inbuilt in Asp.net
Web Applications can't access resources on the system....
Quote:
Server.MapPath()
will Attach the preceeding url of your website...or whatever..
Correct this one first youll get the result....ask in me for more scroll queries...
ThatThatGuy's Avatar
Member
 
Join Date: Jul 2009
Location: Mumbai--India
Posts: 44
#4: Jul 30 '09

re: Next/Previous Record


One more advice don't put &nbsp 's for spaces just put up space....your code was too unreadable....
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,137
#5: Jul 30 '09

re: Next/Previous Record


??
  is HTML for space.....

Where did you see this?
Member
 
Join Date: Jul 2009
Posts: 41
#6: Jul 30 '09

re: Next/Previous Record


lol, I was wondering that too.

Anyways, problem resolved.
Frinavale's Avatar
Site Moderator
 
Join Date: Oct 2006
Location: The Great White North
Posts: 5,137
#7: Jul 30 '09

re: Next/Previous Record


Glad you fixed it :)
ThatThatGuy's Avatar
Member
 
Join Date: Jul 2009
Location: Mumbai--India
Posts: 44
#8: Jul 31 '09

re: Next/Previous Record


Actually frinavale when i was viewing the code part of the post it was showing  's between Dim and the variable names.....Might be some browser problem......think so....Any ways did the solution proved to be useful enough
Member
 
Join Date: Jul 2009
Posts: 41
#9: Jul 31 '09

re: Next/Previous Record


No, it had nothing to do with the paths.

Just had to read up on datareaders and datatables, and such.
Reply