I am trying to create a csv file for the customer to load it to xsl instead of viewing it from the gridview. I did create a link and i am just wondering if i am on the right track. so far i am getting this error msg: operator'&' is not defined for types 'char' and system.date.tablecollection'. thanks
Imports System.Data
Imports System.Data.OracleClient
Imports System.Text.StringBuilder
Imports System.Configuration.ConfigurationManager
Partial Class OneItemPerLine
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
' Dim connectionString As String
If Not IsPostBack Then
Dim oOracleConn As OracleConnection
Dim connectionString As String = ConnectionStrings("ConnectionString").ConnectionString
oOracleConn = New OracleConnection(connectionString)
'Dim oOracleConn As OracleConnection = New OracleConnection(ConfigurationManager.AppSettings("OneItemConn")).ConnectionString
Dim sql As String = " SELECT DISTINCT IDESCR,IUNITS "
sql = sql & "FROM "
sql = sql & "ITEMLIST "
'oOracleConn.Open()
'create a new command and pass our sql statement and our connection object.
Dim myCommand1 As New OracleCommand(sql, oOracleConn)
'open the connection
oOracleConn.Open()
'create a new sqladapter and set its command object with our sqlcommand
Dim myAdapter1 As New OracleDataAdapter(myCommand1)
'create a new dataset to hold our data
Dim myDataSet As New DataSet
'fill the dataset with the result of our query from the specified command
myAdapter1.Fill(myDataSet, "OneItem")
'Bind the DataSet to the GridView
gvCustomers.DataSource = myDataSet
gvCustomers.DataBind()
'Close the connection
End If
End Sub
Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
Dim myDataSet As New DataSet
Dim filename As String
Dim i As Integer
Dim sb As System.Text.StringBuilder
filename = "phllist.csv"
For i = 0 To myDataSet.Tables(0).Columns.Count - 1
If i < (myDataSet.Tables(0).Columns.Count - 1) Then
sb.Append(Chr(34)&(myDataSet.Tables[0].Columns.ColumnName & Chr(34)) & ",")
Else
sb.Append(Chr(34)&(myDataSet.Tables[0].Columns.ColumnName & Chr(34)) & vbCrLf)
End If
Next
Response.ContentType = "Application/x-csv"
Response.AddHeader("content-disposition", "attachment;filename=""" & filename & """")
Response.Write(sb.ToString)
Response.End()
End Sub
End Class
Imports System.Data
Imports System.Data.OracleClient
Imports System.Text.StringBuilder
Imports System.Configuration.ConfigurationManager
Partial Class OneItemPerLine
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
' Dim connectionString As String
If Not IsPostBack Then
Dim oOracleConn As OracleConnection
Dim connectionString As String = ConnectionStrings("ConnectionString").ConnectionString
oOracleConn = New OracleConnection(connectionString)
'Dim oOracleConn As OracleConnection = New OracleConnection(ConfigurationManager.AppSettings("OneItemConn")).ConnectionString
Dim sql As String = " SELECT DISTINCT IDESCR,IUNITS "
sql = sql & "FROM "
sql = sql & "ITEMLIST "
'oOracleConn.Open()
'create a new command and pass our sql statement and our connection object.
Dim myCommand1 As New OracleCommand(sql, oOracleConn)
'open the connection
oOracleConn.Open()
'create a new sqladapter and set its command object with our sqlcommand
Dim myAdapter1 As New OracleDataAdapter(myCommand1)
'create a new dataset to hold our data
Dim myDataSet As New DataSet
'fill the dataset with the result of our query from the specified command
myAdapter1.Fill(myDataSet, "OneItem")
'Bind the DataSet to the GridView
gvCustomers.DataSource = myDataSet
gvCustomers.DataBind()
'Close the connection
End If
End Sub
Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
Dim myDataSet As New DataSet
Dim filename As String
Dim i As Integer
Dim sb As System.Text.StringBuilder
filename = "phllist.csv"
For i = 0 To myDataSet.Tables(0).Columns.Count - 1
If i < (myDataSet.Tables(0).Columns.Count - 1) Then
sb.Append(Chr(34)&(myDataSet.Tables[0].Columns.ColumnName & Chr(34)) & ",")
Else
sb.Append(Chr(34)&(myDataSet.Tables[0].Columns.ColumnName & Chr(34)) & vbCrLf)
End If
Next
Response.ContentType = "Application/x-csv"
Response.AddHeader("content-disposition", "attachment;filename=""" & filename & """")
Response.Write(sb.ToString)
Response.End()
End Sub
End Class