| Author |
Topic Search Topic Options
|
the boss
Senior Member
Joined: 19 January 2003
Location: Saudi Arabia
Status: Offline
Points: 1727
|
Post Options
Thanks(0)
Quote Reply
Topic: best method of opening recordsets 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..
|
 |
Bunce
Senior Member
Joined: 10 April 2002
Location: Australia
Status: Offline
Points: 846
|
Post Options
Thanks(0)
Quote Reply
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.
|
 |
the boss
Senior Member
Joined: 19 January 2003
Location: Saudi Arabia
Status: Offline
Points: 1727
|
Post Options
Thanks(0)
Quote Reply
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..
|
 |
Boecky
Groupie
Joined: 23 December 2002
Location: Belgium
Status: Offline
Points: 110
|
Post Options
Thanks(0)
Quote Reply
Posted: 30 June 2003 at 3:43am |
I think this is the best way for reading:
<%@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 %>
|
 |
Gary
Senior Member
Joined: 20 March 2002
Location: United Kingdom
Status: Offline
Points: 326
|
Post Options
Thanks(0)
Quote Reply
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.
|
 |
Boecky
Groupie
Joined: 23 December 2002
Location: Belgium
Status: Offline
Points: 110
|
Post Options
Thanks(0)
Quote Reply
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
|
 |
the boss
Senior Member
Joined: 19 January 2003
Location: Saudi Arabia
Status: Offline
Points: 1727
|
Post Options
Thanks(0)
Quote Reply
Posted: 30 June 2003 at 5:20am |
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 !!
|
 |
Bunce
Senior Member
Joined: 10 April 2002
Location: Australia
Status: Offline
Points: 846
|
Post Options
Thanks(0)
Quote Reply
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
Edited by Bunce
|
|
There have been many, many posts made throughout the world...
This was one of them.
|
 |