My ASP Tutorials - Select Statement Example
Working With Databases -- The Select Statement:
The first task to master, when working with databases, is the select statement. What the select statement allows
the user to do is to display the results of a database search that was either kicked of via the user or via the webpage.
The syntax is quite easy to master as you can tell by taking a look at either of the two examples featured below.
<%@ Language=VBScript %>
<%
Dim dcnDB
Dim strDatabaseLocation
Dim rsCat
Dim strSQL
strDatabaseLocation = "C:\your_database.mdb"
Set dcnDB = Server.CreateObject("ADODB.Connection")
dcnDB.ConnectionString = _
"Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Persist Security Info=False;Data Source=" _
& strDatabaseLocation
dcnDB.Open
%>
<html>
<head><title>Example of a select statement</title></head>
<body>
<%
strSQL = "SELECT ColumnName, ColumnName FROM TableName WHERE ColumnName = 'Value'"
Set rsCat = dcnDB.execute(strSQL)
%>
</body>
</html>
<% dcnDB.close %>
-----------------------------------------------------------
<%@ Language=VBScript %>
<%
Dim dcnDB
Dim strDatabaseLocation
Dim rsCat
Dim strSQL
Set dcnDB = Server.CreateObject("ADODB.Connection")
dcnDB.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=\\folder\folder
\your_database.mdb")
%>
<html>
<head><title>Example of a select statement</title></head>
<body>
<%
strSQL = "SELECT ColumnName, ColumnName FROM TableName WHERE ColumnName = 'Value'"
Set rsCat = dcnDB.execute(strSQL)
%>
</body>
</html>
<% dcnDB.close %>