Print Page | Close Window

best method of opening recordsets

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=3925
Printed Date: 30 March 2026 at 3:25am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: best method of opening recordsets
Posted By: the boss
Subject: best method of opening recordsets
Date Posted: 29 June 2003 at 6:06am

whats is the most optimised way of opening recordsets in asp along with cursor and lock type option...respond with a code if u can..




Replies:
Posted By: Bunce
Date Posted: 29 June 2003 at 6:13pm
depends what you need it for

-------------
There have been many, many posts made throughout the world...
This was one of them.


Posted By: the boss
Date Posted: 29 June 2003 at 7:50pm

well i need example for inserting, updating deleting and reading opreations... in simple word.. i need a code template..



Posted By: Boecky
Date Posted: 30 June 2003 at 3:43am

I think this is the best way for reading:

<mailto:%@LANGUAGE="VBscript'>%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>

'***Declare variables
Dim Conn
Dim rsTest
Dim ConnStr

'***Connectionstring
ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\test\testdb.mdb"

'***Make connection with the database
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open ConnStr

'***Make a recordset
Set rsTest = Server.CreateObject("ADODB.Recordset")
rsTest.CursorLocation=adUseServer 'Or use number 2
rsTest.CursorType=adOpenForwardOnly 'Or use number 0
rsTest.LockType=adLockReadOnly 'Or use number 1
rsTest.ActiveConnection = Conn
rsTest.Source = "Select * FROM table"
rsTest.Open
%>

...

<%
'***Close recordset and connection

rsTest.Close
Conn.Close
Set rsTest = Nothing
Set Conn = Nothing
%>



Posted By: Gary
Date Posted: 30 June 2003 at 4:38am

Also, 0it is more efficient to wrap all the db related output within a response.write rather than opening and closing the asp tags....

More Efficient
Response.Write("<tr><td>" & rs("myColumn1") & "</td></tr>")
Response.Write("<tr><td>" & rs("myColumn2") & "</td></tr>")

Less Efficient
<tr><td><%=rs("myColumn1")%></td></tr>
<tr><td><%=rs("myColumn2")%></td></tr>

Having said that, personally I prefer to use the LESS effiecient method. Not sure why - possibly old habit (before I learnt the difference in performance), readability of the code, or the pain of dealing with multiple single/double quotes.



Posted By: Boecky
Date Posted: 30 June 2003 at 4:51am
And does anyone also know the CursorLocation, CursorType, LockType for insert, update and delete? Coz I also was looking around for these question Tkx


Posted By: the boss
Date Posted: 30 June 2003 at 5:20am
Originally posted by Boecky Boecky wrote:

I think this is the best way for reading:

this is very similar to the recordsets generated by dreamweaver MX.. well all i do mostly is to make record set using dreamweaver and then copy paste it.. since i dont develop any application for live enviroment use.. most of them r just play around and for easing to explain my idea to others !!



Posted By: Bunce
Date Posted: 30 June 2003 at 5:25am

Actually, the most efficient way of reading a recordset would be to transfer it to an array using getrows() or getstring(), or use a disconnected recordset.

Also the differences in ASP3 between using HTML within Response.write or on its own are negligible, so use what is best for you (and others) to program, understand and troubleshoot.

For those moving to .Net, and in fact many other languages, it would be advisable to try and separate your presentation code from your logic code as much as possible.

Cheers,
Andrew



-------------
There have been many, many posts made throughout the world...
This was one of them.


Posted By: Boecky
Date Posted: 01 July 2003 at 5:11am

thanks for the answers, but the question was actually which CursorLocation, CursorType, LockType for insert, update and delete to use? Just the standard things...does anyone knows that?



Posted By: Bunce
Date Posted: 01 July 2003 at 5:16am
Originally posted by the boss the boss wrote:

whats is the most optimised way of opening recordsets in asp

is exactly what i answered. if you want to ask a different question then start a new thread.



-------------
There have been many, many posts made throughout the world...
This was one of them.



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net