|
 |
asp_databases thread: HELP!!! Need help with Access DB queries ASAP
Message #1 by chrscote@9... on Sun, 6 Oct 2002 20:03:04
|
|
I need some serious help with updating my ASP skills for accessing an
Access Database. I have a DSN established on a server called Baseball
which contains (among others) a table named "Batters" (exact
capitalization). It has been a very long time since the last time I wrote
a page using ASP and cannot remember how to set up the connection and
query a database in ASP. Could someone please help me figure out the code
from just starting a connection to the point where I set up a recordset?
Thank you,
Chris Cote
Message #2 by "Peter Foti (PeterF)" <PeterF@S...> on Mon, 7 Oct 2002 09:47:40 -0400
|
|
Since you are using DSN, there's nothing special about your connection
string.
<%
' Create connection string
Dim ConnStr
ConnStr = "DSN=MyDatabase;Database=MyDatabase;UID=sa;PWD=;"
' Open a connection
Dim dConn
Set dConn = Server.CreateObject("ADODB.Connection")
dConn.Open ConnStr
' Create a query
SQLStr = "SELECT * FROM MyTable"
' Store the results of a query in a recordset
Dim oRS
Set oRS = Server.CreateObject("ADODB.Recordset")
Set oRS = dConn.Execute( SQLStr, , adCmdText )
' Loop through the recordset
Do While Not oRS.EOF
Response.Write( "<div>" )
Response.Write( oRS("MyField") )
Response.Write( "</div>" )
oRS.MoveNext
Loop
' Close the recordset
oRS.Close
Set oRS = Nothing
' Close the connection
dConn.Close
Set dConn = Nothing
%>
Don't forget to include the ADOvbs.inc file.
Hope this helps.
Regards,
Pete
> -----Original Message-----
> From: chrscote@9... [mailto:chrscote@9...]
> Sent: Sunday, October 06, 2002 8:03 PM
> To: ASP Databases
> Subject: [asp_databases] HELP!!! Need help with Access DB queries ASAP
>
>
> I need some serious help with updating my ASP skills for accessing an
> Access Database. I have a DSN established on a server called
> Baseball
> which contains (among others) a table named "Batters" (exact
> capitalization). It has been a very long time since the last
> time I wrote
> a page using ASP and cannot remember how to set up the connection and
> query a database in ASP. Could someone please help me figure
> out the code
> from just starting a connection to the point where I set up a
> recordset?
>
> Thank you,
> Chris Cote
>
|
|
 |