在Web窗体中Crystal Report Viewer显示空白 [英] In Web form Crystal Report Viewer displaying blank

查看:378
本文介绍了在Web窗体中Crystal Report Viewer显示空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi

I'm new in Webform with Crystal Report in visual studio 2012 and framework 4.5. I able to build a Crystal report in web form. But it not displaying any thing. Here I will describe what I did.







1.下载CRforVS_13_0_5.exe 并安装。



2.创建数据集(dbDemo.xsd)



3.创建一个。我的ASP.NET项目中的rpt文件(CRReport.rpt)。并设置数据库字段



4.以下是我显示报告的代码



C#CODE






1. Download "CRforVS_13_0_5.exe" and installed.

2. create dataset (dbDemo.xsd)

3. Create a .rpt file(CRReport.rpt) in my ASP.NET project. and Set the database field

4. Below is my code to display the report

C#CODE

using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;











protected void Page_Load(object sender,EventArgs e)

{

ReportDocument rptDoc = new ReportDocument();

dbDemo ds = new dbDemo(); // .xsd文件名

DataTable dt = new DataTable();



//只需设置数据表的名称

dt.TableName =DATA;

dt = getorder(); //这个函数位于这个函数下面

ds.Tables [0] .Merge(dt);



//你的.rpt文件路径将在下面

rptDoc.Load(Server.MapPath(CRReport.rpt));



//将数据集设置为报告查看器。

rptDoc.SetDataSource(ds);

rptDoc.SetDatabaseLogon(tps_ideal,idealpw);

CrystalReportViewer1。 ReportSource = rptDoc;



CrystalReportViewer1.DisplayToolbar = true;









}

公共DataTable getorder()

{//连接字符串用数据库替换'databaseservername'服务器名称

SqlConnection MyConn = new SqlConnection(ConfigurationManager.ConnectionStrings [DBConnectionString]。ConnectionString);

// SqlConnection Con = new SqlConnectio n(MyConn);

SqlCommand cmd = new SqlCommand();

DataSet ds = null;

SqlDataAdapter适配器;

尝试

{

MyConn.Open();

//存储过程调用。它已经在示例数据库中了。

cmd.CommandText =BindReportView;

cmd.CommandType = CommandType.StoredProcedure;



cmd.Parameters.AddWithValue(@ DOCID,Doc / 001);

cmd.Parameters.AddWithValue(@ DOCNAME,Test Roshni Doc / 001) ;

cmd.Connection = MyConn;

ds = new DataSet();

adapter = new SqlDataAdapter(cmd);

adapter.Fill(ds,Users);

}

catch(Exception ex)

{

抛出新的例外(ex.Message);

}

终于

{

cmd。 Dispose();

if(MyConn.State!= ConnectionState.Closed)

MyConn.Close();

}

返回ds.Tables [0];

}







< br $>


HTML CODE








protected void Page_Load(object sender, EventArgs e)
{
ReportDocument rptDoc = new ReportDocument();
dbDemo ds = new dbDemo(); // .xsd file name
DataTable dt = new DataTable();

// Just set the name of data table
dt.TableName = "DATA";
dt = getorder(); //This function is located below this function
ds.Tables[0].Merge(dt);

// Your .rpt file path will be below
rptDoc.Load(Server.MapPath("CRReport.rpt"));

//set dataset to the report viewer.
rptDoc.SetDataSource(ds);
rptDoc.SetDatabaseLogon("tps_ideal", "idealpw");
CrystalReportViewer1.ReportSource = rptDoc;

CrystalReportViewer1.DisplayToolbar = true;




}
public DataTable getorder()
{//Connection string replace 'databaseservername' with your db server name
SqlConnection MyConn = new SqlConnection(ConfigurationManager.ConnectionStrings["DBConnectionString"].ConnectionString);
//SqlConnection Con = new SqlConnection(MyConn);
SqlCommand cmd = new SqlCommand();
DataSet ds = null;
SqlDataAdapter adapter;
try
{
MyConn.Open();
//Stored procedure calling. It is already in sample db.
cmd.CommandText = "BindReportView";
cmd.CommandType = CommandType.StoredProcedure;

cmd.Parameters.AddWithValue("@DOCID", "Doc/001");
cmd.Parameters.AddWithValue("@DOCNAME", "Test Roshni Doc/001");
cmd.Connection = MyConn;
ds = new DataSet();
adapter = new SqlDataAdapter(cmd);
adapter.Fill(ds, "Users");
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
finally
{
cmd.Dispose();
if (MyConn.State != ConnectionState.Closed)
MyConn.Close();
}
return ds.Tables[0];
}





HTML CODE

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Demo.aspx.cs" Inherits="Sample.Demo" %>

<%@ Register Assembly="CrystalDecisions.Web, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" Namespace="CrystalDecisions.Web" TagPrefix="CR" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" AutoDataBind="true" />
    </div>
    </form>
</body>
</html>







我不知道知道观看我们需要添加任何东西itional。当我调试时,我在我的数据集中获取值testds




I don't know for viewing we need anything additional. When I debugging, I'm getting the value in my dataset "testds"

推荐答案

检查此Exapmle我希望这会对你有所帮助......



http://aspsnippets.com/Articles/Crystal-Report-ASPNet-Example-using-DataSet-or-DataTable-in-C-VBNet-and-Visual-Studio-2010.aspx [ ^ ]
Check this Exapmle i hope this will help you...

http://aspsnippets.com/Articles/Crystal-Report-ASPNet-Example-using-DataSet-or-DataTable-in-C-VBNet-and-Visual-Studio-2010.aspx[^]


这篇关于在Web窗体中Crystal Report Viewer显示空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆