ASP 101 - Active Server Pages 101 - Web01
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:
' Selected constants from
Const adOpenStatic = 3
Const adLockPessimistic = 2
Dim cnnExcel
Dim rstExcel
Dim I
Dim iCols
' This is all standard ADO except for the connection string.
' You can also use a DSN instead, but so it'll run out of the
' box on your machine I'm using the string instead.
Set cnnExcel = Server.CreateObject("ADODB.Connection")
cnnExcel.Open "DBQ=" & Server.MapPath("xl_data.xls") & ";" & _
	"DRIVER={Microsoft Excel Driver (*.xls)};"
' Same as any other data source.
' FYI: TestData is my named range in the Excel file
Set rstExcel = Server.CreateObject("ADODB.Recordset")
rstExcel.Open "SELECT * FROM TestData;", cnnExcel, _
	adOpenStatic, adLockPessimistic
' Get a count of the fields and subtract one since we start
' counting from 0.
iCols = rstExcel.Fields.Count
<table border="1">
		' Show the names that are contained in the first row
		' of the named range.  Make sure you include them in
		' your range when you create it.
		For I = 0 To iCols - 1
			Response.Write "<th>"
			Response.Write rstExcel.Fields.Item(I).Name
			Response.Write "</th>" & vbCrLf
		Next 'I
	' Loop through the data rows showing data in an HTML table.
	Do While Not rstExcel.EOF
		Response.Write "<tr>" & vbCrLf
		For I = 0 To iCols - 1
			Response.Write "<td>"
			Response.Write rstExcel.Fields.Item(I).Value
			Response.Write "</td>" & vbCrLf
		Next 'I
		Response.Write "</tr>" & vbCrLf
Set rstExcel = Nothing
Set cnnExcel = Nothing

Back the the Sample Output

Back to the Sample Index

Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback
The Network for Technology Professionals



Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers