I am using this code to create a csv file and for some hidden reason I am not able to see my out put . I named my csv file filename="products.csv". can someone advise me what is wrong with this code.I do not get any error message but there is not result either.
thanks
<%@ import namespace="System.Data.OleDb"%>
<html>
<head>
<title>connecting to a Database using vb</title></head>
<script runat="server" language="VB">
dim i As Integer
dim filename as string
dim sb as System.Text.StringBuilder
dim cn as OleDbConnection
dim cmd as OleDbCommand
dim dr as OleDbDataReader
dim a as string
Sub Button1_Click(ByVal sender as System.Object, ByVal e as System.EventArgs)
cn = New OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;"& _
"Data Source=c:\Inetpub\ & _
"Dorknozzle.mdb")
filename="products.csv"
cmd = New OleDbCommand("Select * from Employees", cn)
cmd.Connection.open()
dr = cmd.ExecuteReader()
sb= New System.Text.StringBuilder
'for field name
For i=0 to dr.FieldCount-1
If i < (dr.FieldCount-1) then
sb.Append(Chr(34)&dr.GetName(i)&Chr(34)&",")
Else
sb.Append(Chr(34)&dr.GetName(i)&Chr(34)& VbCrLf)
End If
next
'for field value
While dr.Read()
For i=0 to dr.FieldCount-1
If i < (dr.FieldCount-1) then
sb.Append(Chr(34)&dr.GetValue(i).ToString & Chr(34)&",")
Else
sb.Append(Chr(34)&dr.GetValue(i).ToString & Chr(34)& VbCrLf)
End if
Next
End while
dr.close()
cn.Close()
Response.ContentType ="Application/x-msexcel"
Response.AddHeader("content-disposition","attachment;filename="""& filename &"""")
Response.Write(sb.ToString)
Response.End()
End Sub
</script>
<body>
<form runat="server">
<asp:Button id="Button1" runat="Server" text="Button22"></asp:Button>
</form>
</body>
</html>
thanks
<%@ import namespace="System.Data.OleDb"%>
<html>
<head>
<title>connecting to a Database using vb</title></head>
<script runat="server" language="VB">
dim i As Integer
dim filename as string
dim sb as System.Text.StringBuilder
dim cn as OleDbConnection
dim cmd as OleDbCommand
dim dr as OleDbDataReader
dim a as string
Sub Button1_Click(ByVal sender as System.Object, ByVal e as System.EventArgs)
cn = New OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;"& _
"Data Source=c:\Inetpub\ & _
"Dorknozzle.mdb")
filename="products.csv"
cmd = New OleDbCommand("Select * from Employees", cn)
cmd.Connection.open()
dr = cmd.ExecuteReader()
sb= New System.Text.StringBuilder
'for field name
For i=0 to dr.FieldCount-1
If i < (dr.FieldCount-1) then
sb.Append(Chr(34)&dr.GetName(i)&Chr(34)&",")
Else
sb.Append(Chr(34)&dr.GetName(i)&Chr(34)& VbCrLf)
End If
next
'for field value
While dr.Read()
For i=0 to dr.FieldCount-1
If i < (dr.FieldCount-1) then
sb.Append(Chr(34)&dr.GetValue(i).ToString & Chr(34)&",")
Else
sb.Append(Chr(34)&dr.GetValue(i).ToString & Chr(34)& VbCrLf)
End if
Next
End while
dr.close()
cn.Close()
Response.ContentType ="Application/x-msexcel"
Response.AddHeader("content-disposition","attachment;filename="""& filename &"""")
Response.Write(sb.ToString)
Response.End()
End Sub
</script>
<body>
<form runat="server">
<asp:Button id="Button1" runat="Server" text="Button22"></asp:Button>
</form>
</body>
</html>