Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Question abour recordsets from an SQL database to webpage and csv/text

I want to know how I can put each entry from the recordset to a csv/excel file. I just have a problem on how to make each entry on each line on excel and inserted to columns with no skipping spaces. The code is running in a loop. So, each line entry of the recordset is different.
Anyone familiar with readline?

here's an example of my programming code:



<% 'dim to declare variables Dim fso Dim tfile
Dim Verified, UID,CID, PaymentMethod,Card,CardName,CardNumber,CardExpiration
Dim AuthNumber,RefNumber,RetrievalCode,SID,ShipLastName,ShipFirstName
Dim ShipAddress1, ShipAddress2,ShipCity,ShipState,ShipPhone,ShipZIP Dim ShipCountry,Secure,PymtVerification ,Shipped,TrackingID
DimTimeShipped,DatePaid,Tax,SH,Total,Notes,Vnote,Processed,searchno,PONum 'set objconn to create connection to SQL database 'then open objconn set objconn= server.createobject("adodb.connection") objconn.open "Provider=SQLOLEDB; Server=webint; database=azone; uid=mwave; pwd=mwave4anson;" 'set rs (record) set to Server.CreateObject("ADODB.recordset") - this creates recordset 'then open recordset "Select * from (TableName) - have recordset open from database table, using objconn. set rs=Server.CreateObject("ADODB.recordset") rs.Open "SELECT [UID], [CID], [PaymentMethod], [SID], [ShipLastName], [ShipFirstName], [ShipAddress1], [ShipAddress2], [ShipCity], [Tax], [SH], [Total] from Purchases", objconn 'set fso to create file system object set fso = Server.CreateObject("Scripting.FileSystemObject") 'set tfile to create txtfile - somefileblah.csv set tfile = fso.CreateTextFile("\WebintwwwrootEleanorsomefileblah.csv", true) Request.ServerVariables("APPL_PHYSICAL_PATH")&"Eleanorsomefileblah.csv" 'set variables to the information within the recordset information UID = rs("uid") CID = rs("cid") PaymentMethod = rs("paymentmethod") SID = rs("sid") ShipLastName = rs("shiplastname") ShipFirstName = rs("shipfirstname") ShipAddress1 = rs("shipaddress1") ShipAddress2 = rs("shipaddress2") ShipCity = rs("shipcity") Tax = rs("tax") SH = rs("sh") Total = rs("total") 'set variable Text1 to have the string of variables UID & "," & CID &...etc Text1 = UID & "," & CID & "," & PaymentMethod & "," & SID & "," & ShipLastName & "," & ShipFirstName & "," & ShipAddress1& "," & ShipAddress2& "," & ShipCity & "," & Tax & "," & SH & "," & Total ' for each x entrys in the recordset fields

do until rs.EOF for each x in rs.Fields Response.Write(x.value) Response.Write(",") tfile.write(x.value & ",")

'if x.value is Null, fieldValue is ";" else field value is if its not null then it sets that same variable to (cStr(x.value)&" ") If IsNull(x.value) then fieldValue = "," Else fieldValue = (cStr(x.value)&" ") End If next Response.Write("")

rs.MoveNext loop 'response write to display message text created Response.Write("
text created
")

'close tfile 'close objconn connection rs.close tfile.Close objconn.close 'set tfile to nothing 'set fso to nothing set tfile=nothing set fso=nothing %>
Sign In or Register to comment.