Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to create a csv file

Status
Not open for further replies.

arada1

MIS
Dec 3, 2006
47
US
I am using the below code to create a csv file and It works fine but the apps that i am working on right now has three different girdviews and I would like to create one csv files for the three of them togher.My question is can i this code to create that....and if it is possible can someone give me a clue how i can accomplish this. thanks


......
drc = CSVLetting.ExecuteReader()
sb = New System.Text.StringBuilder

'for field name
For i = 0 To drc.FieldCount - 1
If i < (drc.FieldCount - 1) Then
sb.Append(Chr(34) & drc.GetName(i) & Chr(34) & ",")
Else
sb.Append(Chr(34) & drc.GetName(i) & Chr(34) & vbCrLf)
End If
Next

'for field value
While drc.Read()
For i = 0 To drc.FieldCount - 1
If i < (drc.FieldCount - 1) Then
sb.Append(Chr(34) & drc.GetValue(i).ToString.Replace(Chr(34), Chr(34) & Chr(34)) & Chr(34) & ",")
Else
sb.Append(Chr(34) & drc.GetValue(i).ToString & Chr(34) & vbCrLf)
End If
Next
End While

drc.Close()
Response.ContentType = "Application/x-csv"
Response.AddHeader("content-disposition", "attachment;filename=""" & filename & """")
Response.Write(sb.ToString)
Response.End()
 
I'm presuming "drc" is one of your datasources so simply use the same code and loop through the other datasources.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top