Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exporting data from SQL 2000 database

Status
Not open for further replies.

redcare

Technical User
May 20, 2001
32
0
0
GB
Hi


Iam trying to export data into a spreadsheet from my browser window.
The code I have got only allows me to output certain fields.
Is there a way to dynamically input the fields I want to export when I click on the button.e.g by bringing up an input window.
I am using the following code.
==============================
<%
Dim oRS
' Script generates CSV file for procurement scorecards
Response.Buffer = TRUE
Response.ContentType = &quot;application/vnd.ms-excel&quot;
'Write column headings
response.write &quot;Server Name&quot; & vbTab & &quot;Site&quot; & vbTab & &quot;Serial_Number&quot; & vbCrLf

'on error resume next
Set oRS = objConn.Execute(&quot;select Name_of_server,Site_Code,Serial_Number from Products&quot;) ' select statement for export
if err <> 0 Then response.write err.description :response.end
Do Until oRS.EOF
'Write out the fields seperated by tabs
response.write oRS(&quot;Name_of_server&quot;) & vbTab & oRS(&quot;Site_Code&quot;) & vbTab & oRS(&quot;Serial_Number&quot;) & vbCrLf
oRS.MoveNext
Loop
oRS.Close(): Set oRS = Nothing
objConn.close: set objConn = nothing
%>
 
Here it's an example
Code:
index.asp

<%
Set Con=Server.CreateObject(&quot;ADODB.Connection&quot;)
dbPath=Server.MapPath(&quot;test.mdb&quot;) 'Server.MapPath(&quot;Raluca.mdb&quot;)
Con.Open &quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=&quot; & dbPath

set rs=Server.CreateObject(&quot;ADODB.Recordset&quot;)

sql=&quot;select top 1 * from test1&quot;
rs.Open sql,con,3,3
%>
<form action=&quot;display.asp&quot; method=post>
<%
for each fld in rs.Fields
%>
<input type=checkbox name=&quot;displayFields&quot; value=&quot;<%=fld.name%>&quot;><%=fld.name%><br>
<%
next
%>
<input type=&quot;submit&quot; value=&quot;Display&quot;>
</form>

and display.asp

<%
Set Con=Server.CreateObject(&quot;ADODB.Connection&quot;)
dbPath=Server.MapPath(&quot;test.mdb&quot;) 'Server.MapPath(&quot;Raluca.mdb&quot;)
Con.Open &quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=&quot; & dbPath

set rs=Server.CreateObject(&quot;ADODB.Recordset&quot;)

if Request(&quot;displayFields&quot;)=&quot;&quot; then Response.End

sql=&quot;select &quot;&request(&quot;displayFields&quot;)&&quot; from test1&quot;
rs.Open sql,con,3,3
%>
<table>
<tr>
<td>
	Nr. Crt
</td>
<%
for each fld in rs.Fields
%>
<td>
	<%=fld.Name%>
</td>
<%
next
%>
</tr>
<%
i=0
while not rs.Eof
i=i+1
%>
<tr>
<td>
	<%=i%>
</td>
<%
for each fld in rs.Fields
%>
<td>
	<%=rs(fld.Name)%>
</td>
<%
next
%>
</tr>
<%
	rs.MoveNext
wend
%>
</table>

This was made for an access database, just change the connection string to what you would need and the querry.

________
George, M
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top