asp.net调用已存在的水晶报表 5
已用CrystalReports2008做好了一个水晶报表,放在了硬盘的某个目录里,想用asp.netC#程序调用显示这个报表,如何实现?是初学者麻烦代码详细些...
已用CrystalReports2008做好了一个水晶报表,放在了硬盘的某个目录里,想用asp.net C #程序调用显示这个报表,如何实现?是初学者麻烦代码详细些
展开
1个回答
展开全部
我很久之前做了一个动态调用水晶报表的代码,VB.net写的:
mports CrystalDecisions.Shared
Imports CrystalDecisions.CrystalReports.Engine
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Collections
Imports System.Web
Imports System.Web.UI
Imports CrystalDecisions.Reporting
Imports CrystalDecisions.ReportSource
Imports System.IO
Partial Class productreport
Inherits System.Web.UI.Page
Private ht As Hashtable
Private mysql As database
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
Dim ReportDoc As New ReportDocument()
Dim logonInfo As New TableLogOnInfo
Dim table As Table
ReportDoc.Load(Server.MapPath("Crproduct.rpt"))
For Each table In ReportDoc.Database.Tables
logonInfo = table.LogOnInfo
With logonInfo.ConnectionInfo
.ServerName = "mis"
.DatabaseName = "sincehome"
.UserID = "sa"
.Password = "sa"
End With
table.ApplyLogOnInfo(logonInfo)
Next table
CrystalReportViewer1.ReportSource = ReportDoc
End If
End Sub
Protected Sub searchbt_click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim dt As DataTable = New DataTable
Dim sql As String = "select * from product where type='" & Me.Ttype.Text & "'"
mysql = New database
dt = mysql.get_table(sql).Tables(0)
Me.CrySource.ReportDocument.Load(Server.MapPath("Crproduct.rpt"))
Me.CrySource.ReportDocument.SetDataSource(dt)
Me.CrySource.DataBind()
Me.CrystalReportViewer1.ReportSource = Me.CrySource
End Sub
End Class
mports CrystalDecisions.Shared
Imports CrystalDecisions.CrystalReports.Engine
Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Collections
Imports System.Web
Imports System.Web.UI
Imports CrystalDecisions.Reporting
Imports CrystalDecisions.ReportSource
Imports System.IO
Partial Class productreport
Inherits System.Web.UI.Page
Private ht As Hashtable
Private mysql As database
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
Dim ReportDoc As New ReportDocument()
Dim logonInfo As New TableLogOnInfo
Dim table As Table
ReportDoc.Load(Server.MapPath("Crproduct.rpt"))
For Each table In ReportDoc.Database.Tables
logonInfo = table.LogOnInfo
With logonInfo.ConnectionInfo
.ServerName = "mis"
.DatabaseName = "sincehome"
.UserID = "sa"
.Password = "sa"
End With
table.ApplyLogOnInfo(logonInfo)
Next table
CrystalReportViewer1.ReportSource = ReportDoc
End If
End Sub
Protected Sub searchbt_click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim dt As DataTable = New DataTable
Dim sql As String = "select * from product where type='" & Me.Ttype.Text & "'"
mysql = New database
dt = mysql.get_table(sql).Tables(0)
Me.CrySource.ReportDocument.Load(Server.MapPath("Crproduct.rpt"))
Me.CrySource.ReportDocument.SetDataSource(dt)
Me.CrySource.DataBind()
Me.CrystalReportViewer1.ReportSource = Me.CrySource
End Sub
End Class
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询