Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: retrieving values frm database and creating an excel file frm them


Message #1 by "Bhanu Shanker" <bhanu271978@y...> on Wed, 21 Feb 2001 07:42:49
	

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>"

 











Message #2 by "Nagendra Pandey" <npandey@h...> on Thu, 22 Feb 2001 20:23:23
I am not sure if this would help



I use below statment at top of the file to retrieve data in excel.



	Response.ContentType = "application/vnd.ms-excel"



This would open the data in excel.

.

> 	

> 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>"

>  

> 

> 

> 

> 

> 


  Return to Index