I was starting reading this tutorial to utilize crystal reports
我开始阅读本教程来使用水晶报表
http://www.codeproject.com/Articles/142064/Step-by-Step-Creation-of-Crystal-Report-using-its
http://www.codeproject.com/Articles/142064/Step-by-Step-Creation-of-Crystal-Report-using-its
I'm facing this situation, in a stored procedure I have to set some parameters to get the query. So I supposed I need to set the dataSource in runtime, but I have no idea about how to send the stored procedure result to crystal reports and show it in runtime (because until I know, if you want to display something in it, you have to import it and select the fields that you want to place it.
我面对这种情况,在一个存储过程中,我必须设置一些参数来获取查询。所以我认为我在运行时需要设置数据源,但我不知道如何发送水晶报表的存储过程结果并显示它在运行时(因为,直到我知道,如果你想要显示的东西,你必须导入它并选择您想要将它的字段。
2 个解决方案
#1
0
using System;
using System.Collections.Generic;
using System.Data;
using System.Net;
using System.Text;
using CrystalDecisions.Web;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
namespace TexERP.ReportCrystal
{
public partial class AccountRegister : System.Web.UI.Page
{
clsSession objSession;
ReportDocument rptDoc;
protected void Page_Load(object sender, EventArgs e)
{
objSession = new clsSession();
rptDoc = new ReportDocument();
if (Session["objSession"] != null)
{
objSession = Session["objSession"] as clsSession;
}
if (!IsPostBack)
{
Session["ReportDataSet"] = null;
}
if (Session["ReportDataSet"] != null)
{
crvAccountReportParameter.ReportSource = (ReportDocument)Session["ReportDataSet"];
}
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
LoadData();
}
protected void LoadData()
{
string pstrType;
pstrType = Request.QueryString["Type"];
DataSet dsData = null;
dsData = objAccountReportBAL.getAccountRegister(Convert.ToInt16(objSession.FyId), int.MinValue, long.MinValue, Convert.ToDateTime(RadDtpFromDate.SelectedDate), Convert.ToDateTime(RadDtpToDate.SelectedDate), pstrType);
rptDoc.Load(Server.MapPath("~/ReportCrystal/Account/Detail/GeneralVoucharRegister.rpt"));
rptDoc.SetDataSource(dsData.Tables[0]);
Session["ReportDataSet"] = rptDoc;
crvAccountReportParameter.ReportSource = rptDoc;
crvAccountReportParameter.DataBind();
}
}
}
You can do like this........
你可以这样做…
#2
0
first make new form for crystal viewre.. add crystal viewer in it..
首先为水晶视图制作一个新表格。在里面添加水晶查看器
add this code in that form
以那种形式添加此代码
public void ShowForm(DataSet pDataSet)
{
CrystalDecisions.Shared.ConnectionInfo ConnInfo = new CrystalDecisions.Shared.ConnectionInfo();
ReportDocument RepDoc = new ReportDocument();
RepDoc.Load(ReportPath With Rpt name);
TableLogOnInfo TableLogOnInfo;
ConnInfo.ServerName = ServerName;
ConnInfo.DatabaseName = ServerDBName;
ConnInfo.UserID = ServerDBUserName;
ConnInfo.Password = ServerDBPassWord;
foreach (Table TableInRep in RepDoc.Database.Tables)
{
TableLogOnInfo = TableInRep.LogOnInfo;
TableLogOnInfo.ConnectionInfo = ConnInfo;
TableInRep.ApplyLogOnInfo(TableLogOnInfo);
}
CryViewer.ReportSource = RepDoc;
RepDoc.Database.Tables[0].SetDataSource(pDataSet);
this.Show();
}
}
#1
0
using System;
using System.Collections.Generic;
using System.Data;
using System.Net;
using System.Text;
using CrystalDecisions.Web;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
namespace TexERP.ReportCrystal
{
public partial class AccountRegister : System.Web.UI.Page
{
clsSession objSession;
ReportDocument rptDoc;
protected void Page_Load(object sender, EventArgs e)
{
objSession = new clsSession();
rptDoc = new ReportDocument();
if (Session["objSession"] != null)
{
objSession = Session["objSession"] as clsSession;
}
if (!IsPostBack)
{
Session["ReportDataSet"] = null;
}
if (Session["ReportDataSet"] != null)
{
crvAccountReportParameter.ReportSource = (ReportDocument)Session["ReportDataSet"];
}
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
LoadData();
}
protected void LoadData()
{
string pstrType;
pstrType = Request.QueryString["Type"];
DataSet dsData = null;
dsData = objAccountReportBAL.getAccountRegister(Convert.ToInt16(objSession.FyId), int.MinValue, long.MinValue, Convert.ToDateTime(RadDtpFromDate.SelectedDate), Convert.ToDateTime(RadDtpToDate.SelectedDate), pstrType);
rptDoc.Load(Server.MapPath("~/ReportCrystal/Account/Detail/GeneralVoucharRegister.rpt"));
rptDoc.SetDataSource(dsData.Tables[0]);
Session["ReportDataSet"] = rptDoc;
crvAccountReportParameter.ReportSource = rptDoc;
crvAccountReportParameter.DataBind();
}
}
}
You can do like this........
你可以这样做…
#2
0
first make new form for crystal viewre.. add crystal viewer in it..
首先为水晶视图制作一个新表格。在里面添加水晶查看器
add this code in that form
以那种形式添加此代码
public void ShowForm(DataSet pDataSet)
{
CrystalDecisions.Shared.ConnectionInfo ConnInfo = new CrystalDecisions.Shared.ConnectionInfo();
ReportDocument RepDoc = new ReportDocument();
RepDoc.Load(ReportPath With Rpt name);
TableLogOnInfo TableLogOnInfo;
ConnInfo.ServerName = ServerName;
ConnInfo.DatabaseName = ServerDBName;
ConnInfo.UserID = ServerDBUserName;
ConnInfo.Password = ServerDBPassWord;
foreach (Table TableInRep in RepDoc.Database.Tables)
{
TableLogOnInfo = TableInRep.LogOnInfo;
TableLogOnInfo.ConnectionInfo = ConnInfo;
TableInRep.ApplyLogOnInfo(TableLogOnInfo);
}
CryViewer.ReportSource = RepDoc;
RepDoc.Database.Tables[0].SetDataSource(pDataSet);
this.Show();
}
}