View Single Post
Old Sep 27th, 2007, 09:05   #1 (permalink)
Monie
Most Reputable Member
 
Join Date: Feb 2004
Location: Borneo
Age: 27
Posts: 1,566
Blog Entries: 2
Send a message via Yahoo to Monie
[SOLVED] Easiest way to open database connection!

Hai,

I was wondering if you guys have a "short-cut" or "simplest easiest way" on how to connect to the database and declare the recordset!

Typically, people will do like this:

Code: Select all
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("/db/northwind.mdb"))
set rs = Server.CreateObject("ADODB.recordset")
rs.Open "Select * from Customers", conn
%>
<body>
..
..
</body>
<%
rs.close
conn.close
%>
or maybe some thing like this:

External Connection:
Code: Select all
<%
Dim MM_connInvoice_STRING
MM_connInvoice_STRING = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("../db/product.mdb")
%>
index.asp
Code: Select all
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="../Connections/connInvoice.asp" -->

<%
Dim rsCustomers
Dim rsCustomers_cmd
Dim rsCustomers_numRows

Set rsCustomers_cmd = Server.CreateObject ("ADODB.Command")
rsCustomers_cmd.ActiveConnection = MM_connInvoice_STRING
rsCustomers_cmd.CommandText = "SELECT * FROM tblCustomer ORDER BY CName ASC" 
rsCustomers_cmd.Prepared = true

Set rsCustomers = rsCustomers_cmd.Execute
rsCustomers_numRows = 0
%>
Thanks..
__________________


Last edited by Monie; Sep 27th, 2007 at 09:07.
Monie is offline   Reply With Quote