Crystal报表查看器根本不显示数据 [英] Crystal report viewer not show data at all
问题描述
我在C#.net 4.0 Web应用程序中编写以下代码。
使用System;
使用System.Collections.Generic;
使用System.Linq;
使用System.Web;
使用System.Web.UI;
使用System.Web.UI.WebControls;
使用CrystalDecisions.CrystalReports.Engine;
使用CrystalDecisions.Shared;
使用System.Data;
使用System.Data.SqlClient;
使用System.Configuration;
public partial class SimpleCrystal1:System.Web.UI.Page
{
protected void Page_Load(object sender,EventArgs e)
{
ReportDocument rptDoc = new ReportDocument();
dsTestCrystal ds = new dsTestCrystal();
DataTable dt = new DataTable();
dt.TableName =Users;
dt = getAllOrders()。Tables [0];
ds.Tables [0] .Merge(dt);
rptDoc.Load(Server .MapPath(SimpleCrystal.rpt));
rptDoc.SetDataSource(ds);
CrystalReportViewer1.ReportSource = rptDoc;
}
public DataSet getAllOrders()
{
string sqlCon = ConfigurationManager.AppSettings [conStr1]。ToString();
SqlConnection Con = new SqlConnection(sqlCon);
SqlCommand cmd = new SqlCommand();
DataSet ds = null;
SqlDataAdapter适配器;
试试
{
Con.Open();
cmd.CommandText =getAllOrders;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = Con;
ds = new DataSet ();
adapter = new SqlDataAdapter(cmd);
adapter.Fill(ds,Users);
}
catch(例外情况)
{
抛出新的例外(ex.Message);
}
终于
{
cmd.Dispose();
if(Con.State!= ConnectionState.Closed)
Con.Close();
}
返回ds;
}
}
I write the following code in C#.net 4.0 web application.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
public partial class SimpleCrystal1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
ReportDocument rptDoc = new ReportDocument();
dsTestCrystal ds = new dsTestCrystal();
DataTable dt = new DataTable();
dt.TableName = "Users";
dt = getAllOrders().Tables[0];
ds.Tables[0].Merge(dt);
rptDoc.Load(Server.MapPath("SimpleCrystal.rpt"));
rptDoc.SetDataSource(ds);
CrystalReportViewer1.ReportSource = rptDoc;
}
public DataSet getAllOrders()
{
string sqlCon = ConfigurationManager.AppSettings["conStr1"].ToString();
SqlConnection Con = new SqlConnection(sqlCon);
SqlCommand cmd = new SqlCommand();
DataSet ds = null;
SqlDataAdapter adapter;
try
{
Con.Open();
cmd.CommandText = "getAllOrders";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = Con;
ds = new DataSet();
adapter = new SqlDataAdapter(cmd);
adapter.Fill(ds, "Users");
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
cmd.Dispose();
if (Con.State != ConnectionState.Closed)
Con.Close();
}
return ds;
}
}
推荐答案
确保你得到运行时DataSet
中的数据。
此问题的可能解决方案。
水晶报告:避免空白页面 [ ^ ]
Crystal报告 - 神秘的空白页面 [ ^ ]
Crystal Report空白/空/不显示。没有屏幕错误,但事件日志'ConfigurationErrorsException'收到 [ ^ ]
编辑
--------------------
Ensure you get data in yourDataSet
in runtime.
Here possible solutions for this issue.
Crystal Reports: Avoiding Blank Pages[^]
Crystal reports - Mysterious blank pages[^]
Crystal Report Blank / Empty / Not Displaying. No On-Screen Error, But Event Log ‘ConfigurationErrorsException’ Received[^]
EDIT
--------------------
dt.TableName = "Crystal Report Example";
对于DataTable来说,这不是一个好名字。确保您的报告的表名称&这个DataTable名称是相同的,如果不相同那么做更改&再试一次。同样检查DataSet(报告和代码)。再试一次。
EDIT2
---------------------
在水晶报告中显示数据 [ ^ ]
Not a good name for a DataTable. Make sure your Report's Table name & this DataTable name are same, if not same then do changes & try again. Also check the same for DataSet(both report & code). Try again.
EDIT2
---------------------
Display data in crystal reports[^]
这篇关于Crystal报表查看器根本不显示数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!