ASP db

From KOP KB
Jump to: navigation, search

For SQL Server

<style>
table{
border-collapse: collapse;
}
td{
border-width: 1px;
border-style: dashed;
border-color: #880000;
padding: 5px;
text-align: center;
}
</style>
<%
	Function ConnectDB()
		Set objConn = Server.CreateObject("ADODB.Connection")
		
		' This is the connection info this will connect the thing to the database
		' uid= username
		'server = server
		'pwd = password
		'database= database
		'This is only for MS SQL driver
		'For others customers can go look at http://connectionstrings.com
		
		objConn.Open "DRIVER={SQL Server};server=sname;uid=uname;pwd=pass;database=db"
		Set ConnectDB = objConn
		
		' These are the connection drivers that are supported through this and dsn		
		' MySQL
		' Microsoft SQL Server
		' Microsoft Access Driver (*.mdb)
		' Microsoft dBase Driver (*.dbf) – dBase 5
		' Microsoft Excel Driver (*.xls)
		' Microsoft Paradox Driver (*.db)
		' Microsoft Text Driver (*.txt or *.csv) 

	End Function
%>

<%
'  In this bracket leave IT ALONE
    Dim myNum
	Dim objConn1
    Dim rsRecords1
	Set objConn1 = Server.CreateObject("ADODB.Connection")
	Set rsRecords1 = Server.CreateObject("ADODB.Recordset")
	Set objConn1 = ConnectDB()
	myNum = 1
%>
<%
     ' You may need to change to this to  an actual table name in their database
	strSQL = "SELECT * FROM markets"
	Set rsRecords1 = objConn1.Execute(strSQL)
	
%>
<table>
<tr>
<%
' Top row of table 
Response.Write "<td>"
Response.Write "market"

'Below is just the extra column headers you can uncomment to add extras name the same as the actual column name

Response.Write "</td><td>"
Response.Write "county"

Response.Write "</td><td>"
Response.Write "st"

Response.Write "</td></tr>"
%>
<% 
' Do not touch this bracket
DO WHILE NOT rsRecords1.EOF 
%>
<tr>
<% 
' You will need to update this to whatever columns they may have in the table only one column copy and paste if you want more
' Uncommenting text in notepad++ is CTRL+Q and that will comment or uncomment that line
' below is for only one record you can uncomment the below to show more than on record

Response.Write "<td>"
Response.Write rsRecords1("market")


Response.Write "</td><td>"
Response.Write rsRecords1("county")

Response.Write "</td><td>"
Response.Write rsRecords1("st")
Response.Write "</td></tr>"
%>
<%
'Do not touch this asp bracket
rsRecords1.MoveNext
Loop
%> 

<%
' Do not touch this asp bracket
	objConn1.Close
	Set objConn1 = Nothing
	Set rsRecords1 = Nothing
%>

Access Database

It appears that some times it is needed to use full path without the drive letter

Set objConn = Server.CreateObject("ADODB.Connection")
objConn.ConnectionString = "provider=Microsoft.Jet.OLEDB.4.0; data source=\\fullpath\dbfolder\dbname.mdb"
objConn.Open