水晶报表 C# Asp.Net 刚刚开始学习水晶报表 想知道 如何操作.rpt 这页。 我创建了显示页 并引入了数据源 及报表页。但是不知道在报表页要如何操作了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 web页面用水晶报表的例子:http://www.orsoon.com/Article/Article_12280.html 1 创建文件dataset 类型,后缀名为xsd的文件,vs 会将该文件建在App_Code文件夹下, 在弹出的选项卡TableAdapter Configuration Wizard 中点击New Connection ,然或配置连接字符串信息,servername ->server Authentication ->select database ,点击确定,回到原选项卡点击Next ,选择Use SQL statements,选择Query Builder 或直接在该步填写sql 的查询语句select * from table ,Next->Next->Finish, rpt的数据源创建完成。2 创建文件CrystalReport 类型,后缀名为rpt的文件,在弹出的选项卡Crystal Reprits Gallery中选择第一项点击ok,在Project Data->ADO.NET DataSets->dataset->刚才的表,填入右侧,点击Next ,选中表双击加入右侧,加入所有字段Next->finish.接下来在报表的主体里点击右键insert ->chart->选择一种图表->ok.Rpt文件创建完成 http://topic.csdn.net/s/DotNETReport/0.htmlhttp://www.cnblogs.com/hanyihua99/archive/2007/09/29/910412.html using CrystalDecisions.CrystalReports.Engine;using CrystalDecisions.Shared;public partial class Report_CRt1 : System.Web.UI.Page{ //使用变量名 customersByCityReport,为 ReportDocument 报表包装类添加新的类级声明。将其访问修饰符设置为 private //ReportDocument 类是 CrystalDecisions.CrystalReports.Engine 命名空间的成员 private ReportDocument customersByCityReport; private void Page_Init(object sender, EventArgs e) { ConfigureCrystalReports();//首先初始化报表; } private void ConfigureCrystalReports() { //此函数配置报表的连接,数据库密码等; ConnectionInfo connectionInfo = new ConnectionInfo(); connectionInfo.ServerName = "."; connectionInfo.DatabaseName = "DataBase"; connectionInfo.UserID = "sa"; connectionInfo.Password = ""; //实例化 ReportDocument 类, 声明一个字符串变量“reportPath”,然后给它分配一个本地报表的运行时路径。 customersByCityReport = new ReportDocument(); string reportPath = Server.MapPath("CrystalReport.rpt"); customersByCityReport.Load(reportPath);//调用 ReportDocument 实例的 Load() 方法,并对其传递 reportPath 字符串变量。 crystalReportViewer.ReportSource = customersByCityReport; SetDBLogonForReport(connectionInfo, customersByCityReport); if (!IsPostBack) { string selectFormula = "{VouchView.cCusName} > \"陈\"";//过滤所有姓陈的客户 crystalReportViewer.SelectionFormula = selectFormula; } else { string selectFormula = "{VouchView.cCusName} like " + "\"*" + ShipRegion.Text + "*\""; crystalReportViewer.SelectionFormula = selectFormula; } } private void SetDBLogonForReport(ConnectionInfo connectionInfo, ReportDocument CityReport) { //此函数设定报表里所有表的连接数据库及密码 TableLogOnInfos tableLogOnInfos = crystalReportViewer.LogOnInfo; foreach (TableLogOnInfo tableLogOnInfo in tableLogOnInfos) { tableLogOnInfo.ConnectionInfo = connectionInfo; } } protected void redisplay_Click(object sender, EventArgs e) { ConfigureCrystalReports(); }} Aspx 页面:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CRt1.aspx.cs" Inherits="Report_CRt1" %><%@ 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>报表页1</title> <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> <asp:Label ID="Label1" runat="server" Text="输入客户:"></asp:Label> <asp:TextBox ID="ShipRegion" runat="server"></asp:TextBox><br /> <asp:Label ID="Label3" runat="server" Text="City:"></asp:Label> <asp:DropDownList ID="CityList" runat="server"> <asp:ListItem>CA</asp:ListItem> <asp:ListItem>WA</asp:ListItem> <asp:ListItem>NM</asp:ListItem> <asp:ListItem>SP</asp:ListItem> <asp:ListItem>RJ</asp:ListItem> </asp:DropDownList><asp:Label ID="message1" runat="server" Text=""></asp:Label><br /> <asp:Button ID="redisplay" runat="server" OnClick="redisplay_Click" Text="显示报表" Width="120px" /><br /> <CR:CrystalReportViewer ID="crystalReportViewer" runat="server" AutoDataBind="true" /> </div> </form></body></html> ConfigureCrystalReports(); 如何从数据库读到的字段,生成一个pdf文档 动态绑定datagridview,要如何清空上次绑定的数据? 在程序中点击下一步、上一步的Form切换如何实现? 不规则的Htmltable 写入Excel 关于想从某个子函数结束应用程序的问题。 关于C#chart的图例位置设定 C# RDLC报表中的某列,怎么按条件小计? 想知道CopyMemory的一些具體的用法-C#.(我沒分了) vs.net有正式D版了吗?! C#的C/S程序中能否集成微信登录二维码功能 菜菜紧急求救 打洞失败
在弹出的选项卡TableAdapter Configuration Wizard 中点击New Connection ,然或配置连接字符串信息,servername ->server Authentication ->select database ,点击确定,回到原选项卡点击Next ,选择Use SQL statements,选择Query Builder 或直接在该步填写sql 的查询语句select * from table ,Next->Next->Finish, rpt的数据源创建完成。
2 创建文件CrystalReport 类型,后缀名为rpt的文件,在弹出的选项卡Crystal Reprits Gallery中选择第一项点击ok,在Project Data->ADO.NET DataSets->dataset->刚才的表,填入右侧,点击Next ,选中表双击加入右侧,加入所有字段Next->finish.
接下来在报表的主体里点击右键insert ->chart->选择一种图表->ok.
Rpt文件创建完成
http://www.cnblogs.com/hanyihua99/archive/2007/09/29/910412.html
using CrystalDecisions.Shared;public partial class Report_CRt1 : System.Web.UI.Page
{
//使用变量名 customersByCityReport,为 ReportDocument 报表包装类添加新的类级声明。将其访问修饰符设置为 private
//ReportDocument 类是 CrystalDecisions.CrystalReports.Engine 命名空间的成员
private ReportDocument customersByCityReport;
private void Page_Init(object sender, EventArgs e)
{
ConfigureCrystalReports();//首先初始化报表;
}
private void ConfigureCrystalReports()
{
//此函数配置报表的连接,数据库密码等;
ConnectionInfo connectionInfo = new ConnectionInfo();
connectionInfo.ServerName = ".";
connectionInfo.DatabaseName = "DataBase";
connectionInfo.UserID = "sa";
connectionInfo.Password = ""; //实例化 ReportDocument 类, 声明一个字符串变量“reportPath”,然后给它分配一个本地报表的运行时路径。
customersByCityReport = new ReportDocument(); string reportPath = Server.MapPath("CrystalReport.rpt");
customersByCityReport.Load(reportPath);//调用 ReportDocument 实例的 Load() 方法,并对其传递 reportPath 字符串变量。
crystalReportViewer.ReportSource = customersByCityReport;
SetDBLogonForReport(connectionInfo, customersByCityReport);
if (!IsPostBack)
{
string selectFormula = "{VouchView.cCusName} > \"陈\"";//过滤所有姓陈的客户
crystalReportViewer.SelectionFormula = selectFormula;
}
else
{
string selectFormula = "{VouchView.cCusName} like " + "\"*" + ShipRegion.Text + "*\"";
crystalReportViewer.SelectionFormula = selectFormula;
}
} private void SetDBLogonForReport(ConnectionInfo connectionInfo, ReportDocument CityReport)
{
//此函数设定报表里所有表的连接数据库及密码
TableLogOnInfos tableLogOnInfos = crystalReportViewer.LogOnInfo;
foreach (TableLogOnInfo tableLogOnInfo in tableLogOnInfos)
{
tableLogOnInfo.ConnectionInfo = connectionInfo;
}
}
protected void redisplay_Click(object sender, EventArgs e)
{
ConfigureCrystalReports();
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CRt1.aspx.cs" Inherits="Report_CRt1" %>
<%@ 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>报表页1</title>
<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>
<asp:Label ID="Label1" runat="server" Text="输入客户:"></asp:Label>
<asp:TextBox ID="ShipRegion" runat="server"></asp:TextBox><br />
<asp:Label ID="Label3" runat="server" Text="City:"></asp:Label>
<asp:DropDownList ID="CityList" runat="server">
<asp:ListItem>CA</asp:ListItem>
<asp:ListItem>WA</asp:ListItem>
<asp:ListItem>NM</asp:ListItem>
<asp:ListItem>SP</asp:ListItem>
<asp:ListItem>RJ</asp:ListItem>
</asp:DropDownList><asp:Label ID="message1" runat="server" Text=""></asp:Label><br />
<asp:Button ID="redisplay" runat="server" OnClick="redisplay_Click" Text="显示报表"
Width="120px" /><br />
<CR:CrystalReportViewer ID="crystalReportViewer" runat="server" AutoDataBind="true" />
</div>
</form>
</body>
</html>