Inherits System.Web.UI.Page '
Private ConnectionString As String = "Data Source=(local);Initial Catalog=pubs;User Id=sa;Password=sa123"
Private cn1 As SqlConnection
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If Not Page.IsPostBack Then
Dim cn As New SqlConnection(ConnectionString)
cn.Open()
cn1 = New SqlConnection(ConnectionString)
cn1.Open()
Dim cmd As New SqlCommand("select * from [authors]", cn)
Dim dr As SqlDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
GridView1.DataSource = dr
GridView1.DataBind()
dr.Close()
End If
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim cn As New SqlConnection(ConnectionString)
cn.Open()
cn1 = New SqlConnection(ConnectionString)
cn1.Open()
Dim ds As New DataSet()
Dim ad As New SqlDataAdapter("select * from [authors]", cn)
ad.Fill(ds)
Dim str As New StringBuilder()
Dim i As Integer
For i = 0 To ds.Tables(0).Rows.Count - 1
Dim j As Integer
For j = 0 To ds.Tables(0).Columns.Count - 1
str.Append(ds.Tables(0).Rows(i)(j).ToString())
Next j
str.Append("<BR>")
Next i
Response.Clear()
Response.AddHeader("content-disposition", "attachment;filename=FileName.txt")
Response.Charset = ""
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.ContentType = "application/vnd.text"
Dim stringWrite As New System.IO.StringWriter()
Dim htmlWrite = New HtmlTextWriter(stringWrite)
Response.Write(str.ToString())
Response.End()
cn.Close()
cn1.Close()
cn.Dispose()
cn1.Dispose()
End Sub
Public Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)
End Sub
End Class