vb WebSite 使用水晶报表

前端之家收集整理的这篇文章主要介绍了vb WebSite 使用水晶报表前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

vb WebSite 使用水晶报表

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default2.aspx.vb" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<%@ Register Assembly="CrystalDecisions.Web,Version=13.0.2000.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 id="Head1" runat="server">
    <title>Untitled Page</title>
    <link href="/aspnet_client/System_Web/2_0_50701/CrystalReportWebFormViewer3/css/default.css"
        rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <CR:CrystalReportViewer ID="crystalReportViewer" runat="server" AutoDataBind="true" 
        HasCrystallogo="False" HasToggleGroupTreeButton="False" ToolPanelView="None" />
    </div>
    </form>
</body>
</html>

后台代码

Imports System
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.Shared

Partial Class Default2
    Inherits System.Web.UI.Page

    Private customerReport As ReportDocument
    Private Sub ConfigureCrystalReports()
        customerReport = New ReportDocument
        Dim reportPath As String = Server.MapPath("CrystalReport2.rpt")
        customerReport.Load(reportPath)
        Dim dataSet As DataSet = DataSetConfiguration.CustomerDataSet
        customerReport.SetDataSource(dataSet)
        crystalReportViewer.ReportSource = customerReport
        crystalReportViewer.ShowFirstPage()

    End Sub

    Protected Sub Page_Load(ByVal sender As Object,ByVal e As System.EventArgs) Handles Me.Load
        ConfigureCrystalReports()
    End Sub
End Class


还有一个关键类 DataSetConfiguration 这个类做连接数据库交互数据。

这个类我是应用 之前的 cs 文件

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;

public class DataSetConfiguration
{
     private const string CONNECTION_STRING = @"Provider=sqlOLEDB;Data Source=.;Password=123456;User ID=sa;Initial Catalog=Garment";// 连接字符串
       private const string QUERY_STRING = "SELECT rights_no,rights_name,module_no,module_name,remark FROM access_rights";
    private const string DATATABLE_NAME = "access_rights";
    private const string DIRECTORY_FILE_PATH = "";

    public static DataSet CustomerDataSet
    {
        get
        {
            DataSet dataSet = new DataSet();
            dataSet.ReadXmlSchema(@"D:\CrystalReports2.0_51aspx\CS_Web_Data_DataSets\CS_Web_Data_DataSets\App_Code\DataSet1.xsd");
            //dataSet.ReadXmlSchema(@"D:\CrystalReports2.0_51aspx\CS_Web_Data_DataSets\CS_Web_Data_DataSets\XMLSchema.xsd");//数据集路径
            OleDbConnection oleDbConnection = new OleDbConnection(CONNECTION_STRING);
            OleDbDataAdapter oleDbDataAdapter = new OleDbDataAdapter(QUERY_STRING,oleDbConnection);
            oleDbDataAdapter.Fill(dataSet,DATATABLE_NAME);
            return dataSet;
        }
    }
}

猜你在找的VB相关文章