Signup · Login
Stardeveloper.com  
Home · Tutorials · Forums · Web Hosting Plans · Faisal Khan's Blog · Contact
Search Stardeveloper.com
Stardeveloper RSS Feed
Newsletter
Enter your email address below to be informed every time a new article is posted at Stardeveloper.com:

You can follow Faisal Khan on Twitter
Article Categories
.NET  .NET
  ASP (16)
  ASP.NET (41)
  ADO (16)
  ADO.NET (10)
  COM (6)
  Web Services (4)
  C# (1)
  VB.NET (3)
  IIS (2)

J2EE  J2EE
  JSP (15)
  Servlets (9)
  Web Services (1)
  EJB (4)
  JDBC (4)
  E-Commerce (1)
  J2ME (1)
  Products (1)
  Applets (1)
  Patterns (1)
Log In
UserName Or Email:

Password:

Auto-Login:

Miscellaneous Links
  Submit Article

Hosted by Securewebs.com
 
Home : .NET : ADO : Speedup Database Access using GetRows
 
' Now Showing Records from our DataSet
Dim i, j
' Creating table to show records
Response.Write "<table align=""center"" border=""1"" width=""70%"""
Response.Write " cellspacing=""1"" cellpadding=""3"" bordercolor=""silver"">"
Response.Write vbcrlf
Response.Write "<tr><td colspan=""" & (UBound(ds, 1) + 1)
Response.Write """ align=""center"">Names</td></tr>"
Response.Write "<tr><td>ID</td><td>First " & _
	"Name</td><td>Last Name</td></tr>"

Here we just create a table and give useful names to it's columns.

	' Showing Each Row
	For i = 0 To UBound(ds, 2)
		Response.Write "<tr>" & vbcrlf
		' Showing Each Column

		For j = 0 To UBound(ds, 1)
			Response.Write "<td>"
			Response.Write ds(j, i)
			Response.Write "</td>"
		Next

		Response.Write "</tr>" & vbcrlf
	Next

Now comes the real part. Here we use two For ... Next loops to show all the records present in the ds array.

	' Showing Each Row
	For i = 0 To UBound(ds, 2)

We first determine the number of rows retrieved by looking at the upper limit of the 2nd dimension of the ds variable. This is how we move row by row, showing the contents of the rows and columns.

	' Showing Each Column
	For j = 0 To UBound(ds, 1)
		Response.Write "<td>"
		Response.Write ds(j, i)
		Response.Write "</td>"
	Next

Then within the For ... Next loop of each row we start a new For ... Next loop to show the content of all the columns.

	Erase ds

Running the ASP page
You should place both the paging.mdb and getrows.asp files in the same directory. Assuming that you placed both of them under /getrows/ directory under your virtual directory, you should use http://127.0.0.1/getrows/getrows.asp URL to see your ASP page on your local computer.

You will notice that the results appear faster than using the usual way of accessing a database. Even if you don't notice that on your own computer, rest assured that the ASP page will run faster and database will be able to handle more requests when a lot more users access them at the same time.

So we saw that there are other faster ways of accessing a database and showing it's results than simply keeping the database connection patent while showing it's records. We learned a very useful Recordset.GetRows method which will retrieve all the records in a recordset into a two dimensional array. We can then using two For ... Next loops show all the contents of that Array and Erase it when we are done.

Remember this
Notice that you can create a Recordset any way you want, like you can open a table, run a query, a stored procedure etc to generate a recordset. Then simply use Recordset.GetRows to get all those records into a two dimensional Array and close the database connection.

I am saying this so that you may not start to think that the only way to create a recordset for creating a two dimensional Array is to open a table like we did in this article. You can create the Recordset anyway you like, like you do normally and just use the Recordset.GetRows method.

Keep learning!

' Now Showing Records from our DataSet
Dim i, j
' Creating table to show records
Response.Write "<table align=""center"" border=""1"" width=""70%"""
Response.Write " cellspacing=""1"" cellpadding=""3"" bordercolor=""silver"">"
Response.Write vbcrlf
Response.Write "<tr><td colspan=""" & (UBound(ds, 1) + 1)
Response.Write """ align=""center"">Names</td></tr>"
Response.Write "<tr><td>ID</td><td>First " & _
	"Name</td><td>Last Name</td></tr>"

Here we just create a table and give useful names to it's columns.

	' Showing Each Row
	For i = 0 To UBound(ds, 2)
		Response.Write "<tr>" & vbcrlf
		' Showing Each Column

		For j = 0 To UBound(ds, 1)
			Response.Write "<td>"
			Response.Write ds(j, i)
			Response.Write "</td>"
		Next

		Response.Write "</tr>" & vbcrlf
	Next

Now comes the real part. Here we use two For ... Next loops to show all the records present in the ds array.

	' Showing Each Row
	For i = 0 To UBound(ds, 2)

We first determine the number of rows retrieved by looking at the upper limit of the 2nd dimension of the ds variable. This is how we move row by row, showing the contents of the rows and columns.

	' Showing Each Column
	For j = 0 To UBound(ds, 1)
		Response.Write "<td>"
		Response.Write ds(j, i)
		Response.Write "</td>"
	Next

Then within the For ... Next loop of each row we start a new For ... Next loop to show the content of all the columns.

	Erase ds

Running the ASP page
You should place both the paging.mdb and getrows.asp files in the same directory. Assuming that you placed both of them under /getrows/ directory under your virtual directory, you should use http://127.0.0.1/getrows/getrows.asp URL to see your ASP page on your local computer.

You will notice that the results appear faster than using the usual way of accessing a database. Even if you don't notice that on your own computer, rest assured that the ASP page will run faster and database will be able to handle more requests when a lot more users access them at the same time.

So we saw that there are other faster ways of accessing a database and showing it's results than simply keeping the database connection patent while showing it's records. We learned a very useful Recordset.GetRows method which will retrieve all the records in a recordset into a two dimensional array. We can then using two For ... Next loops show all the contents of that Array and Erase it when we are done.

Remember this
Notice that you can create a Recordset any way you want, like you can open a table, run a query, a stored procedure etc to generate a recordset. Then simply use Recordset.GetRows to get all those records into a two dimensional Array and close the database connection.

I am saying this so that you may not start to think that the only way to create a recordset for creating a two dimensional Array is to open a table like we did in this article. You can create the Recordset anyway you like, like you do normally and just use the Recordset.GetRows method.

Keep learning!


Previous ( 1 Gone )( No Further Pages )

See all comments and questions (post-ad) posted for this tutorial.


Download Associated Files
2000080601.zip

Related Articles
  1. How to display records from top 4 database systems using plain ASP?
  2. Uploading Files into an Access Database using plain ASP
  3. Displaying Images from an Access Database using plain ASP
  4. Fastest way of Database Access : Caching Records in Memory
  5. Adding records to the database with ASP
  6. DSN vs DSN less Database Connections
  7. Searching and sorting records in a recordset from the database
  8. Inserting Form content into Database with ASP
  9. Using ASP pages to page through Recordsets
  10. Generating Random Records from the Database

Comments/Questions ( Threads: 1, Comments: 2 )
    Contains 1 or more replies by the Author of this Article.
    Contains 1 or more replies by Faisal Khan.

  1. Does it really speed things up??? ( 1 Reply ) This thread contains 1 reply by the Author of this Article. This thread contains 1 reply by Faisal Khan.

Post Comments/Questions

In order to post questions/comments, you must be logged-in. If you are not a member yet, then signup, otherwise login. Once you login then come back to this page and you'll see a form right here which will allow you to post comments/questions.

Please note, one of the benefits of signing up is to be notified immediately by email everytime you receive a reply to the thread you have subscribed to.

 
© 1999 - 2009 Stardeveloper.com, All Rights Reserved.