ASP 101 - Active Server Pages 101 - Web04
The Place ASP Developers Go!

Please visit our partners

Windows Technology Windows Technology
15 Seconds
ASP 101
ASP Wire
VB Forums
VB Wire
internet.commerce internet.commerce
Partners & Affiliates

ASP 101 is an site
ASP 101 is an site
Internet News
Small Business
Personal Technology

Corporate Info
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash

ASP Source Code:
Dim objDC, objRS
' Create and establish data connection
Set objDC = Server.CreateObject("ADODB.Connection")
objDC.ConnectionTimeout = 15
objDC.CommandTimeout = 30
'Use this line to use Access
'objDC.Open "DBQ=" & Server.MapPath("database.mdb") & ";Driver={Microsoft Access Driver (*.mdb)};DriverId=25;MaxBufferSize=8192;Threads=20;", "username", "password"
'Our SQL Server code - use above line to use sample on your server
objDC.Open "Provider=SQLOLEDB;Data Source=;" _
	& "Initial Catalog=samples;Connect Timeout=15;" _
	& "Network Library=dbmssocn;", "samples", "password"
' Create recordset and retrieve values using the open connection
Set objRS = Server.CreateObject("ADODB.Recordset")
' Opening record set with a forward-only cursor (the 0) and in read-only mode (the 1)
' If a request for a specific id comes in, then do it o/w just show pulldown
If Len(Request.QueryString("id")) <> 0 Then
	' request record for requested id
	objRS.Open "SELECT * FROM sample WHERE id = " & Replace(Request.QueryString("id"), "'", "''"), objDC, 0, 1
	' Show selected record
	If Not objRS.EOF Then
		<table border="2">
				<td><strong>ID Number</strong></td>
				<td><strong>First Name</strong></td>
				<td><strong>Last Name</strong></td>
				<td><strong>Month's Sales</strong></td>
				<td align="center"><%= objRS.Fields("id") %></td>
				<td align="left"><%= objRS.Fields("first_name") %></td>
				<td align="left"><%= objRS.Fields("last_name") %></td>
				<td align="right"><%= objRS.Fields("sales") %></td>
	End If
End If
objRS.Open "sample", objDC, 0, 1
' Loop through recordset and display results
If Not objRS.EOF Then
	' the form below calls this file only this time with an id in the QueryString
	<form action="db_pulldown.asp" method="get">
	<select name="id">
	' Continue until we get to the end of the recordset.
	Do While Not objRS.EOF
		' For each record we create a option tag and set it's value to the employee id
		' The text we set to the employees first name combined with a space and then their last name
		<option value="<%= objRS.Fields("id") %>"><%= objRS.Fields("first_name") & " " & objRS.Fields("last_name") %></option>
	' Get next record
	<input type="submit" value="Submit" />
End If
' Close Data Access Objects and free DB variables
Set objRS =  Nothing
Set objDC = Nothing

Back the the Sample Output

Back to the Sample Index

Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback


WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs