Hi Yama,
Here's some code that will send a CSV file to Excel. Is that what you
needed?
Private Sub Button1_Click _
(ByVal sender As System.Object, _
ByVal e As System.EventArg s) _
Handles Button1.Click
'Set the appropriate ContentType.
Dim filename As String = "orderdetails.c sv"
Dim myCommand As New SqlCommand _
("select * from [order details] ", SqlConnection1)
myCommand.Conne ction.Open()
Dim myReader As SqlDataReader = _
myCommand.Execu teReader _
(CommandBehavio r.CloseConnecti on)
Dim i As Integer
Dim sb As New System.Text.Str ingBuilder
For i = 0 To myReader.FieldC ount - 1
If i < (myReader.Field Count - 1) Then
sb.Append(Chr(3 4) & myReader.GetNam e(i) & _
Chr(34) & ",")
Else
sb.Append(Chr(3 4) & myReader.GetNam e(i) & _
Chr(34) & vbCrLf)
End If
Next
While myReader.Read()
For i = 0 To myReader.FieldC ount - 1
If i < (myReader.Field Count - 1) Then
sb.Append(Chr(3 4) & _
myReader.GetVal ue(i).ToString & Chr(34) & ",")
Else
sb.Append(Chr(3 4) & _
myReader.GetVal ue(i).ToString & Chr(34) & vbCrLf)
End If
Next
End While
myReader.Close( )
SqlConnection1. Close()
Response.Conten tType = "Applicatio n/x-msexcel"
Response.AddHea der _
("content-disposition", "attachment ; filename=""" & _
filename & """")
'Write the file directly to the HTTP output stream.
Response.Write( sb.ToString)
Response.End()
End Sub
"Yama" <yk*****@grandp acificresorts.c om> wrote in message
news:eE******** ******@TK2MSFTN GP09.phx.gbl...
Hi,
I am looking to create a report comma delimited on a click of a button.
Explanantion:
1. Get from the database: "SELECT * FROM Customers WHERE Region = 'CA'"
2. Use either DataReader or DataSource
3. Create a button "Export"
4. On ServerClick Event prompt user to save as a text comma delimited
file.
Can someone help me?
Yama