dbWriter Quick database table connection ASP code
Use this Quick connection table to check your database table and
query string. Connect to a SQL database or a Access database:
Click here to test this code on an Access
database
<%@ Language=VBScript %>
<% Option Explicit %>
<HTML>
<HEAD>
<TITLE>DbWriter Quick Table</TITLE>
<style>
body {font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
color: #000000;
}
TH {font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 12px;
color: #FFFFFF;
}
.n {background-color: #F5F5F5;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #000000;
}
.z { background-color: #FFFFFF;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
color: #000000;
}
</style>
</HEAD>
<BODY>
<h2>dbWriter quick DB table</h2>
<%
DIM DBConnect
DIM strSQL
DIM rs
DIM QArray
DIM Value
DIM I, J
DIM strbgcolor
Server.ScriptTimeout = 90
DIM DBConnect_SQLServer
DIM DBConnect_UserName
DIM DBConnect_Password
DIM DBConnect_DB
DIM strCon, strSQLDB
DIM DBConnect_Con
DIM AccessDB_Path
DIM AccessDB_NAME
On Error Resume next
'== SQL database required connection string entries
=============
DBConnect_UserName = "??????????" 'SQL server username
DBConnect_Password = "??????????" 'SQL server password
DBConnect_SQLServer = "??????????" 'SQL server usually an IP
address
strSQLDB = "??????????" 'SQL server database
'== SQL server UN-COMMENT the the SQL connection string
Set DBConnect_Con = Server.CreateObject("ADODB.Connection")
'strCon = "Provider=SQLOLEDB;Server=" & DBConnect_SQLServer &
";User ID=" & DBConnect_UserName & ";Password=" &
DBConnect_Password & ";Database=" & strSQLDB & ";"
'=========================================================END
SQL setup
'== Access database required connection string entries
============
AccessDB_Path = "\db\" 'Access database directory
AccessDB_Name = "YOUR.mdb" 'Access database name
'== FOR ACCESS UN-COMMENT the the ONLY ONE of the Access connection
drivers ===================
'strCon = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" &
Server.MapPath(AccessDB_Path & AccessDB_Name) & ";"
strCon = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" &
Server.MapPath(AccessDB_Path & AccessDB_Name) & ";"
'========================================================END
Access setup
DBConnect_Con.connectionstring = strCon
DBConnect_Con.Open
'== Setup your query here
=============================================================
strSQL = "SELECT * FROM bookmaster"
Set rs = DBConnect_Con.Execute(strSQL)
if Err.Number <> 0 THEN
%>
<br>
<TABLE BORDER="0" CELLSPACING="1" CELLPADDING="1" BGCOLOR="#000080"
WIDTH="90%">
<tr>
<td BGCOLOR="#FFFFFF">Err.Source</td>
<td BGCOLOR="#FFFFFF"><%= Err.Source %></td>
</tr>
<tr>
<td BGCOLOR="#FFFFFF">Err.Number</td>
<td BGCOLOR="#FFFFFF"><%= Err.Number %></td>
</tr>
<tr>
<td BGCOLOR="#FFFFFF">Err.Description</td>
<td BGCOLOR="#FFFFFF"><%= Err.Description %></td>
</tr>
</table>
<%
response.end
end if
If Not rs.EOF Then
QArray = rs.GetRows()
%>
<P>Total number of records: <%= CStr(UBound(QArray, 2)) %></P>
<TABLE BORDER="0" CELLSPACING="1" CELLPADDING="1" BGCOLOR="#000080"
WIDTH="90%">
<TR BGCOLOR="#000080">
<%
'output field headings
For I = 0 To UBound(QArray, 1)
%>
<TH ALIGN="left"><B><%= Trim(rs.Fields(I).Name) %></TH>
<%
Next
rs.Close
Set rs = Nothing
DBConnect_Con.Close
Set DBConnect_Con = Nothing
%>
</TR>
<%
For I = 0 To UBound(QArray, 2)
Response.Write "<TR>"
For J = 0 to UBound(QArray, 1)
Value = Trim(QArray(J, I))
If IsNull(Value) Then Value = "NULL"
If i mod 2 = 0 Then
strbgcolor= "class=""n"" "
Else
strbgcolor= "class=""z"" "
End If
%>
<TD ALIGN="left" <%=strbgcolor%> ><%= Value %></TD>
<%
Next
Response.Write "</TR>"
Next
%>
</TABLE>
<%
Else
Response.Write "Done"
End If
%>
</BODY>
</HTML>
|
|