第一:创建RPT报表文件,具体请google一下,很多的
第二:主页面
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="FumiRpt.aspx.vb" Inherits="Rpt_FumiRpt" Title="XXX报告单" %>
<%@ Register Assembly="CrystalDecisions.Web, Version=10.2.3600.0, Culture=neutral, PublicKeyToken=692fbea5521e1304"
Namespace="CrystalDecisions.Web" TagPrefix="CR" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<link href="/aspnet_client/System_Web/2_0_50727/CrystalReportWebFormViewer3/css/default.css"
rel="stylesheet" type="text/css" />
<link href="/aspnet_client/System_Web/2_0_50727/CrystalReportWebFormViewer3/css/default.css"
rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<div>
<CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="true" />
<CR:CrystalReportSource ID="CrystalReportSource1" runat="server">
<Report FileName="FumiRpt.rpt">
</Report>
</CR:CrystalReportSource>
</div>
</form>
</body>
</html>
第三、代码页
Imports System
Imports System.Data
Imports System.Configuration
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared
Imports FumiSys
Partial Class Rpt_FumiRpt
Inherits System.Web.UI.Page
Public Sub BindReport(ByVal Fumi_no As String)
Dim myConnection As New SqlClient.SqlConnection
myConnection.ConnectionString = "Data Source=ZIQ-HZ-LH;Initial Catalog=FumiData;User ID=sa;password=978138"
Dim Mycommand As New SqlClient.SqlCommand
Mycommand.Connection = myConnection
Mycommand.CommandText = "SELECT * FROM View_Fumi_Fee where Fumi_no='" & Fumi_no & "'"
Mycommand.CommandType = CommandType.Text
Dim MyDA As New SqlClient.SqlDataAdapter
MyDA.SelectCommand = Mycommand
Dim myDS As New FumiSys
MyDA.Fill(myDS, "view_Fumi_Fee")
Dim RptDoc As New ReportDocument()
Dim reportPath As String = HttpRuntime.AppDomainAppPath + "//crystalrpt//fumirpt.rpt" 'Server.MapPath("~/crystalRpt/FumiRpt.rpt") Dim reportPath As String = HttpRuntime.AppDomainAppPath + "//crystalrpt//fumirpt.rpt" 'Server.MapPath("~/crystalRpt/FumiRpt.rpt")
'Dim reportPath As String = Server.MapPath("FumiRpt.rpt")
' northwindCustomersReport.Load(reportPath)
' reportPath = "d:/My Documents/Visual Studio 2005/WebSites/FumisysWeb/FumiRpt.rpt"
RptDoc.Load(reportPath)
RptDoc.SetDataSource(myDS) '这里就是引用的关键了
CrystalReportViewer1.ReportSource = RptDoc '在CrystalReportViewer上显示
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim fumi_no As String = Request.QueryString("id")
BindReport(fumi_no)
End Sub
End Class