'文件名:QueryConsumePrint.aspx.vb
Imports System.Data.SqlClient
Imports System.Data
Partial Class QueryManage_QueryConsumePrint
Inherits System.Web.UI.Page
Private MyQueryConsumeForm As QueryManage_QueryConsumeForm
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'将查询结果输出到Excel文件中
MyQueryConsumeForm = Context.Handler
Dim MySQL As String = MyQueryConsumeForm.MyPrintSQL
Dim My商品名称 As String = MyQueryConsumeForm.MyPrint商品名称
Dim My开始日期 As String = MyQueryConsumeForm.MyPrint开始日期
Dim My结束日期 As String = MyQueryConsumeForm.MyPrint结束日期
Me.Label1.Text = Session("MyCompanyName").ToString() + "消费商品分类统计表"
Me.Label2.Text = "开始日期:" + My开始日期 + " 结束日期:" + My结束日期 + " 商品名称:" + My商品名称
Dim MyConnectionString As String = ConfigurationManager.ConnectionStrings("MyHotelDBConnectionString").ConnectionString
Dim MyAdapter As New SqlDataAdapter(MySQL, MyConnectionString)
Dim MySet As New DataSet()
MyAdapter.Fill(MySet)
Me.DataGrid1.DataSource = MySet
Me.DataGrid1.DataBind()
Me.Response.ContentType = "application/vnd.ms-excel"
Me.Response.Charset = ""
'关闭 ViewState
Me.EnableViewState = False
Dim MyWriter As System.IO.StringWriter
Dim MyWeb As System.Web.UI.HtmlTextWriter
'将信息写入字符串
MyWriter = New System.IO.StringWriter()
'在Web窗体页上写出一系列连续的HTML特定字符和文本
MyWeb = New System.Web.UI.HtmlTextWriter(MyWriter)
'将DataGrid中的内容输出到HtmlTextWriter对象中
Me.DataGrid1.RenderControl(MyWeb)
'把HTML写回浏览器
Response.Write(MyWriter.ToString())
End Sub
End Class