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!

Unable to see CSV file

Status
Not open for further replies.

dawtes

Programmer
Jun 23, 2005
31
US
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>
 
did you do a view source? what does it give???

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top