By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,413 Members | 1,594 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,413 IT Pros & Developers. It's quick & easy.

Export datas to a Excel file using query without openrowset method

P: 12
Hi all,
Can any one tell me,
Export datas to a Excel file using query without openrowset method

is there any other methods are posible

for creating an Excel file to export it

Thanks,
Babu.K
Nov 24 '09 #1
Share this Question
Share on Google+
1 Reply


P: 2
@baburmm
Try the code below, it works

<%@ Language=VBScript %>
<%
'Change HTML header to specify Excel's MIME content type
Response.Buffer = TRUE
Response.ContentType = "application/vnd.ms-excel"


%>
<HTML>
<BODY>
<p>
<%
' Create ADO Connection object
dim myConnection
Dim I
Dim myRecordset
Dim sqlStr
set myConnection = Server.CreateObject("ADODB.Connection")
set myRecordset = Server.CreateObject("ADODB.Recordset")
'Open SQL Server Pubs database...
myConnection.Open "DSN=myweb;uid=abc;password=abc;Database=dbnam e"

'Get a recordset of info from Authors table...
sqlStr = "SELECT * from SUPPLIER"' where empm_empid = 'E0123'"
'sqlstr =Request.QueryString("qry")
'sqlstr=session("excelqry")

'response.write sqlstr
'response.end
I=1
set rsAuthors = myConnection.Execute(sqlStr)
%>

<!-- Our table which will be translated into an Excel spreadsheet -->
<TABLE WIDTH=75% BORDER=1 CELLSPACING=1 CELLPADDING=1>
<!-- server-side loop adding Table entries -->
<% do while not rsAuthors.EOF %>

<% if I=1 then %>
<TR>
<% I=I+1 %>
<% For Each fld In rsAuthors.Fields %>
<TD><%=fld.name %></TD>
<% next %>
</TR>
<% end if %>


<TR>

<% For Each fld In rsAuthors.Fields %>
<TD><%=fld.value %></TD>
<% next %>
</TR>
<% rsAuthors.MoveNext
loop
' Clean up
rsAuthors.Close
set rsAuthors = Nothing
myConnection.Close
set myConnection = Nothing
%>
</TABLE>
</BODY>
</HTML>
Nov 24 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.