These are the error message i am getting and do not know what to do i am fairly new to asp.net can someone help.
thanks
Type 'sqldatareader' is not defined.
Type 'sqlconnection' is not defined.
Type 'sqlCommand' is not defined.
Name 'CommandBehaviour' is not declared.
Public Class WebForm1
Inherits System.Web.UI.Page
<%@import namespace="system.data.oledb"%>
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
Dim cn As sqlconnetion
Dim cmd As sqlcommand
Dim filename As String
Dim dr As sqldatareader
Dim sb As System.Text.StringBuilder
cn = New sqlconnection("server=localhost;uid=sa;pwd=;database=northwind")
filename = "prdouct.csv"
cmd = New sqlCommand("select * from products", cn)
cmd.connection.Open()
dr = cmd.ExecuteReader(CommandBehaviour.CloseConnection)
sb = New System.Text.StringBuilder()
'For fiedl Names
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 values
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.Getname(i) & Chr(34) & vbCrLf)
End If
Next
End While
dr.close()
cn.close()
Response.ContentType = "application/x-msexcel"
Response.AddHeader("content-disposition", "attachment;filename=""" & filename & """")
'write the file directly to the HTTP output stream.
Response.Write(sb.ToString)
Response.End()
End Sub
End Class
thanks
Type 'sqldatareader' is not defined.
Type 'sqlconnection' is not defined.
Type 'sqlCommand' is not defined.
Name 'CommandBehaviour' is not declared.
Public Class WebForm1
Inherits System.Web.UI.Page
<%@import namespace="system.data.oledb"%>
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
Dim cn As sqlconnetion
Dim cmd As sqlcommand
Dim filename As String
Dim dr As sqldatareader
Dim sb As System.Text.StringBuilder
cn = New sqlconnection("server=localhost;uid=sa;pwd=;database=northwind")
filename = "prdouct.csv"
cmd = New sqlCommand("select * from products", cn)
cmd.connection.Open()
dr = cmd.ExecuteReader(CommandBehaviour.CloseConnection)
sb = New System.Text.StringBuilder()
'For fiedl Names
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 values
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.Getname(i) & Chr(34) & vbCrLf)
End If
Next
End While
dr.close()
cn.close()
Response.ContentType = "application/x-msexcel"
Response.AddHeader("content-disposition", "attachment;filename=""" & filename & """")
'write the file directly to the HTTP output stream.
Response.Write(sb.ToString)
Response.End()
End Sub
End Class