doorbreaker
Programmer
Hi I need to create a CSV. At the moment, it works perfectly but the user has to submit the form. How do I get it to create the CSV when the page is called. I am going to use a scheduled task eventually.
This is what currently works:
Thanks for any help.
Chris
This is what currently works:
Code:
<%
on error resume next
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.cursorlocation=3
objconn.Open "driver={sql server};server=xxx.xxx.xxx.xxx;database=mydb;uid=myuid;pwd=mypwd"
if err.number then
response.write "Could not connect to database server:<BR>"
response.write err.Description
response.end
end if
%>
<%
strSQL = "select * from table"
Set rst = objconn.Execute(strSQL)
if request("download")>"" then
'response.addheader "content-type","application/vnd.ms-excel"
response.addheader "content-type","application/ms-excel"
response.addheader "content-encoding","none"
response.addheader "content-disposition","inline; filename=generatedcsv.csv"
response.write "Category Type FieldC FieldD
FieldE FieldF FieldG FieldH FieldI FieldJ FieldK SKU Description Promotion Image LinkToProduct Price DeliveryCost DeliveryTime Availability Warranty Condition OfferType Bid" & vbcrlf
while not rst.eof
UniqueCode = rst("productID")
Name = rst("title")
Description = rst("ShortDesc")
Description = replace(Description,",",",")
LinkToProduct = "[URL unfurl="true"]http://www.mysite.com/product.asp?pid="[/URL] & UniqueCode
Image = "[URL unfurl="true"]http://www.mysite.com/productimages/"[/URL] & rst("imgmain")
Price = rst("Price")
Price = formatnumber(Price,2)
response.write "Gadgets MySite "& Name &" "& UniqueCode &" "& Description &" "& Image &" "& LinkToProduct &" "& Price &" ""Free 1-3 Days Yes Yes
New " & vbcrlf
iItems = iItems + rst("qty")
iValue = iValue + cdbl(rst("value"))
iCount = iCount + rst("count")
rst.movenext
wend
rst.close
set rst=nothing
objconn.close
set objconn=nothing
response.end
end if
%>
<form method="post" name="frm">
<TABLE align="center">
<TR>
<TD align="center"><IMG SRC="images/logo.gif" BORDER="0" ALT=""></TD>
</TR>
<TR>
<TD class="black12" align="center">Product CSV Download Page<br><br></TD>
</TR>
<TR>
<TD class="black12" align="center"><input type="hidden" name="download" value="">
<input type="button" class="actbut" value="Download CSV" onclick="frm.download.value='Y';frm.submit();"></TD>
</TR>
</TABLE>
</form>
Thanks for any help.
Chris