Click to See Complete Forum and Search --> : where is the error?why I can not export the report?


lisho
April 8th, 2003, 01:06 AM
webform1.aspx.vb:

Imports System
Imports System.Data
Imports System.Web.UI
Imports System.Web
Imports System.Web.UI.Control
Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents DropDownList1 As System.Web.UI.WebControls.DropDownList
Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents Label3 As System.Web.UI.WebControls.Label
Protected WithEvents Label2 As System.Web.UI.WebControls.Label
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents Label4 As System.Web.UI.WebControls.Label
Protected WithEvents Label5 As System.Web.UI.WebControls.Label
Protected WithEvents TextBox2 As System.Web.UI.WebControls.TextBox
Protected WithEvents TextBox3 As System.Web.UI.WebControls.TextBox
Protected WithEvents Label6 As System.Web.UI.WebControls.Label
Protected WithEvents Label7 As System.Web.UI.WebControls.Label
Protected WithEvents TextBox4 As System.Web.UI.WebControls.TextBox
Protected WithEvents Label8 As System.Web.UI.WebControls.Label
Protected WithEvents RequiredFieldValidator1 As System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents RequiredFieldValidator2 As System.Web.UI.WebControls.RequiredFieldValidator
Protected WithEvents Button2 As System.Web.UI.HtmlControls.HtmlInputButton
Protected WithEvents DropDownList2 As System.Web.UI.WebControls.DropDownList

#Region " Web 窗体设计器生成的代码 "

'该调用是 Web 窗体设计器所必需的。
<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: 此方法调用是 Web 窗体设计器所必需的
'不要使用代码编糭器修改它。
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
Dim strConnection As String = "user id=sa; password=;"
strConnection += "database=salesys;server=LI_XIANG\lx;"
Dim strSql As String = "select distinct customer_id,company_name from jianglijinchaxun "
Dim objConnection As SqlConnection = New SqlConnection(strConnection)
Dim objDataset As New DataSet()
Dim objDataadapter As New SqlDataAdapter(strSql, objConnection)
objDataadapter.Fill(objDataset, "jianglijinchaxun")
Dim objDataview As New DataView(objDataset.Tables("jianglijinchaxun"))
Dim objTable As DataTable
objTable = objDataset.Tables("jianglijinchaxun")

Dim strCustomer_id(65) As String
Dim i As Integer
For i = 0 To 64
strCustomer_id(i) = objTable.Rows(i).Item("customer_id")
Next

Dim strid As String
For Each strid In strCustomer_id
DropDownList1.Items.Add(strid)
Next


'产品的代码绑定
End Sub

Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
Dim strConnection As String = "user id=sa; password=;"
strConnection += "database=salesys;server=LI_XIANG\lx;"
Dim strSql As String = "select distinct customer_id,company_name from jianglijinchaxun "
Dim objConnection As SqlConnection = New SqlConnection(strConnection)
Dim objDataset As New DataSet()
Dim objDataadapter As New SqlDataAdapter(strSql, objConnection)
objDataadapter.Fill(objDataset, "jianglijinchaxun")
Dim objDataview As New DataView(objDataset.Tables("jianglijinchaxun"))
Dim objTable As DataTable
objTable = objDataset.Tables("jianglijinchaxun")
If DropDownList1.SelectedItem.Value = "" Then
TextBox1.Text = ""
Else
TextBox1.Text = objTable.Rows(DropDownList1.SelectedIndex).Item("company_name")
End If

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Response.Redirect("webform2.aspx?customerid=" + Server.UrlEncode(DropDownList1.SelectedItem.Value) + "&productid=" + Server.UrlEncode(DropDownList2.SelectedItem.Value) _
+ "&startdate=" + Server.UrlEncode(TextBox2.Text) + "&enddate=" + Server.UrlEncode(TextBox3.Text))
End Sub




End Class



webform2.aspx.vb



Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Data
Imports System.Web
Imports System.Web.SessionState
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports CrystalDecisions.Shared
Imports CrystalDecisions.CrystalReports.Engine

Public Class WebForm2
Inherits System.Web.UI.Page
Dim strCustomerid As String
Dim strProductid As String
Dim strStartdate As String
Dim strEnddate As String
Protected WithEvents CrystalReportViewer1 As CrystalDecisions.Web.CrystalReportViewer
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Dim objdocument As New ReportDocument()
#Region " Web 窗体设计器生成的代码 "

'该调用是 Web 窗体设计器所必需的。
<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: 此方法调用是 Web 窗体设计器所必需的
'不要使用代码编糭器修改它。
InitializeComponent()

End Sub

#End Region

Public Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码

strCustomerid = Request.QueryString.Get("customerid")
strProductid = Request.QueryString.Get("productid")
strStartdate = DateTime.Parse(Request.QueryString.Get("startdate"))
strEnddate = DateTime.Parse(Request.QueryString.Get("enddate"))

setreportparameters()

objdocument.Load("c:\\inetpub\\wwwroot\\asp\\report1\\CrystalReport1.rpt")
CrystalReportViewer1.ReportSource = objdocument
End Sub
Public Sub setreportparameters()
'声明一个集合用来装参数对象
Dim paramFields As New ParameterFields()
'将要传递的参数段
Dim pfcustomerid As New ParameterField()
Dim pfproductid As New ParameterField()
Dim pfstartdate As New ParameterField()
Dim pfenddate As New ParameterField()
'设置惨数字段名
pfcustomerid.ParameterFieldName = "pcustomerid"
pfproductid.ParameterFieldName = "pproductid"
pfstartdate.ParameterFieldName = "pstartdate"
pfenddate.ParameterFieldName = "penddate"
'以上参数字段要被秘密对象接受
'声明秘密对象
Dim dccustomerid As New ParameterDiscreteValue()
Dim dcproductid As New ParameterDiscreteValue()
Dim dcstartdate As New ParameterDiscreteValue()
Dim dcenddate As New ParameterDiscreteValue()
'设置值给秘密对象
dccustomerid.Value = strCustomerid
dcproductid.Value = strProductid
dcstartdate.Value = strStartdate
dcenddate.Value = strEnddate
'在参数中加入秘密值
pfcustomerid.CurrentValues.Add(dccustomerid)
pfproductid.CurrentValues.Add(dcproductid)
pfstartdate.CurrentValues.Add(dcstartdate)
pfenddate.CurrentValues.Add(dcenddate)
'现在把所有的参数字段加入集合
paramFields.Add(pfcustomerid)
paramFields.Add(pfproductid)
paramFields.Add(pfstartdate)
paramFields.Add(pfenddate)
'最后把集合加入到报表中
CrystalReportViewer1.ParameterFieldInfo = paramFields

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' 声明变量并获取导出选项。
Dim exportOpts As New ExportOptions()
Dim DiskOpts As CrystalDecisions.Shared.DiskFileDestinationOptions = New CrystalDecisions.Shared.DiskFileDestinationOptions()
Dim excelFormatOpts As New ExcelFormatOptions()
exportOpts = objdocument.ExportOptions

' 设置 Excel 格式选项。
excelFormatOpts.ExcelTabHasColumnHeadings = True

objdocument.ExportOptions.ExportFormatType = ExportFormatType.Excel
objdocument.ExportOptions.FormatOptions = excelFormatOpts


' 设置导出格式。
exportOpts.ExportFormatType = ExportFormatType.Excel

exportOpts.ExportDestinationType = ExportDestinationType.DiskFile

' 设置磁盘文件选项并导出。
DiskOpts.DiskFileName = "c:\output.xls"
objdocument.ExportOptions.DestinationOptions = DiskOpts

objdocument.Export()

End Sub
end class