p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

proasp_codeclinic thread: Re: retrieving values from database and converting them into excel file


Message #1 by =?iso-8859-1?q?Bhanu=20Shanker=20Menon?= <bhanu271978@y...> on Tue, 20 Feb 2001 23:29:54 -0800 (PST)
	
Hi there,

Iam writing a code that retrieves the values from a
database and makes it into an excel file(creates a
report). But here when I run this code, the browser
displays an error that " page cannot be displayed".
	Could any one help me out to solve this problem.

BHANU 

Below is the code which i have used:
	
	Set con=Server.CreateObject("ADODB.Connection")
	Set rs=Server.CreateObject("ADODB.RecordSet")
	con.ConnectionString = "driver={SQL Server};"&_
		"server=Ipaddress;uid=sa;pwd=;database=pubs"
			con.Open
sql="Select * from users" 
		rs.Open sql,con

	fname="Report.xls"
	Set
fso=Server.CreateObject("Scripting.FileSystemObject")
	Set fil=fso.CreateTextFile(fname,True)	
		
	For each x in rs.fields
          
            strLine= strLine & x.name & chr(9)
          Next

       
          fil.writeline strLine

         'Retrieve the values from the database and
write into the database
          Do while Not rs.EOF
          strLine=""
          for each x in rs.Fields
            strLine= strLine & x.value & chr(9)
          next
          fil.writeline strLine
          rs.MoveNext
       Loop

       fil.Close
       Set fil=Nothing
       Set fso=Nothing

       link="<A HREF=" & fname & ">Open Excel</a>"
 








__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - Buy the things you want at great prices! http://auctions.yahoo.com/

  Return to Index