Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 Other Development Tools
 import data from SQL database to MS Excel by ASP

Author  Topic 

friscapjtn
Starting Member

8 Posts

Posted - 2009-08-20 : 00:14:48
How to import data from SQL database to MS Excel by ASP.

For example, already added a long list of contact people (name, phone, email, address...) in a table on the SQL server, how can I just upload the file from the table on the SQL server to transfer the data to the excel file by ASP code, but it must using parameters date, year and month?

Any help will be most appreciated!


----file1.asp----
<form id="form1" name="form1" action="file2.asp" method="post">

<table border="0" width="600" cellspacing="1" cellpadding="0">
<tr>
<td width="140" class="CellHeader">Tanggal</td>
<td width="450">
<SELECT id=selectmonth name=selectmonth>
<%
for I = 01 to 12
Response.Write(vbNewLine)
if I = Month(date) then
Response.Write("<OPTION selected value=" & MonthName(I) & ">" & MonthName(I) & "</OPTION>")
else
Response.Write("<OPTION value=" & MonthName(I) & ">" & MonthName(I) & "</OPTION>")
end if
next
%>
</SELECT>
<SELECT id=selectyear name=selectYear>
<%
for I = 2000 to 2111
Response.Write(vbNewLine)
if I = Year(date) then
Response.Write("<OPTION selected value=" & I & ">" & I & "</OPTION>")
else
Response.Write("<OPTION value=" & I & ">" & I & "</OPTION>")
end if
next
%>
</SELECT>
</td>
</table>
<input type="submit" name="submit" value="Generate!">
</form>


-----file2.asp-----

varBln = Request("selectmonth")
varthn = Request("selectyear")

dim rstStt, cmdSP, parSP
set rstStt = server.CreateObject("ADODB.Recordset")
set cmdSP = server.CreateObject("ADODB.Command")

cmdSP.ActiveConnection =con5
cmdSP.CommandType = 4
cmdSP.CommandText = "vof_generateRisk"
cmdSP.Parameters.Refresh


Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "Content-Disposition", "attachment; filename=Excel" & request.form("objTable") & ".xls"



Hmmm....
   

- Advertisement -