Creating Crystal report with C# and Sql server(使用 C# 和 Sql server 创建 Crystal 报表)
问题描述
我正在使用 Crystal 报告为我的应用程序生成报告,这是我使用的代码:
I'm using Crystal report to generate reports to my application, this is the code i used:
private void button5_Click(object sender, EventArgs e)
{
ReportDocument cryRpt = new ReportDocument();
TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
ConnectionInfo crConnectionInfo = new ConnectionInfo();
Tables CrTables;
cryRpt.Load("C:\Documents and Settings\Administrateur\Mes documents\MyApplication\MyApplication\CrystalReport1.rpt");
crConnectionInfo.ServerName = ".\SQLEXPRESS";
crConnectionInfo.DatabaseName = "database";
crConnectionInfo.UserID = "";
crConnectionInfo.Password = "";
crConnectionInfo.IntegratedSecurity = true;
CrTables = cryRpt.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
{
crtableLogoninfo = CrTable.LogOnInfo;
crtableLogoninfo.ConnectionInfo = crConnectionInfo;
CrTable.ApplyLogOnInfo(crtableLogoninfo);
}
cryRpt.SetDatabaseLogon("", "", ".\SQLEXPRESS", "database");
crystalReportViewer1.ReportSource = cryRpt;
crystalReportViewer1.Refresh();
}
但是当我运行应用程序时,会出现一个登录屏幕并要求连接 ID 和密码,我尝试输入空值,但连接失败.
But when i run the application, a login screen appeared and demands the connection Id and password, i tried to enter null values but the connection is failed.
问题出在哪里??
推荐答案
你必须初始化 DataSet 类的一个实例,并用来自的信息填充它
You have to initialize an instance of the DataSet class, and fill it with information from
您的数据集,因为 Crystal 报表数据源基于数据集.这是一个基本的代码
your DataSet because Crystal report Datasource is based on a dataset. This is a basic code of
将 Crystal 报表与数据集一起使用:
using Crystal report with Dataset:
SqlConnection con = new SqlConnection();
con.ConnectionString = @"Data Source=.SQLEXPRESS;AttachDbFilename=YOUR PATHdatabase.mdf;Integrated Security=True;User Instance=True";
con.Open();
string sql = "SELECT * FROM tablename";
SqlDataAdapter dscmd = new SqlDataAdapter(sql, con);
DataSet ds = new DataSet();
dscmd.Fill(ds, "tablename");
con.Close();
CrystalReport1 objRpt = new CrystalReport1();
objRpt.SetDataSource(ds.Tables["tablename"]);
crystalReportViewer1.ReportSource = objRpt;
crystalReportViewer1.Refresh();
这篇关于使用 C# 和 Sql server 创建 Crystal 报表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 C# 和 Sql server 创建 Crystal 报表
基础教程推荐
- 将 XML 转换为通用列表 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 如何激活MC67中的红灯 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01