如何使用asp.net中的一个数据集绑定来自多个数据表的Crystal Report C# [英] how to bind crystal report from multiple datatables using one dataset in asp.net c#

查看:60
本文介绍了如何使用asp.net中的一个数据集绑定来自多个数据表的Crystal Report C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用asp.net c#中的一个数据集从多个数据表绑定Crystal报表?

how to bind crystal report from multiple datatables using one dataset in asp.net c#?

推荐答案

亲爱的,您需要为此创建一个Add Command并在其中您为此指定了联合查询.
这是通过使用添加命令完成的...

另一件事是您需要创建连接查询以从不同表中返回值"

例如..此示例显示了与不同数据库不同的地方...

Dear , you need to create a Add Command for that and in that you specify Union Query for that.
this done in using the ADD COMMAND...

and another thing is that "You need to Create Join Query for Return the Value from Different Table"

for Example..this example shows different from different database...

select * from db1.dbo.cust_list where Condtion
union all
select * from db2.dbo.cust_list where condition
union all
select * from db3.dbo.cust_list where condition



确保您的查询从所有数据库返回相同数量的列..



如有疑问,请发布....



make sure your Query Returns same number of Columns from all database..



if any query, please post it....


水晶报表为我带来了很多问题.其中之一是如何使用一个数据集从多个数据表中绑定水晶报表?
但是现在我自己解决了这个问题
1)首先我在查询中使用联接,但是在数据源中我无法给出表名
然后在其中创建使用联接查询的视图
联接查询是:-

Crystal reports create so much problems for me. one of them was how to bnd crystal report from multiple datatables using one dataset?
but now i solved this problem myself
1) firstly i was using joins in query but in datasource i was unable to give table name
then i create view in which i use join query
join query is:-

SELECT        companymaster.address, companymaster.tin, saleitemadd.vch, saleitemadd.item, saleitemadd.qty, saleitemadd.rate,
                         saleitemadd.amount, saleitemadd.tax, saleitemadd.totaltax, saleitemadd.totalamount, saleitemadd.companyname, saleitemadd.party,
                         saleitemadd.date1, saleitemadd.discount
FROM            companymaster INNER JOIN
                         saleitemadd ON companymaster.companyname = saleitemadd.companyname AND
                         companymaster.companyname = saleitemadd.companyname





然后执行查询并保存视图,然后在数据集中添加tableadapter,然后选择视图"选项卡,然后选择我的视图表.

之后,我创建水晶报表并调用数据集并选择视图表

在C#中,我使用这些代码行
公共局部类saleitemvoucherbill:System.Web.UI.Page
{
字符串strConn;
SqlConnection con =新的SqlConnection();
SqlCommand cmd =新的SqlCommand();
DataSet ds = new DataSet("salereport");
私人ReportDocument rptDoc = null;
受保护的void Page_Load(对象发送者,EventArgs e)
{
strConn = ConfigurationManager.ConnectionStrings ["ConnectionASPX"].ConnectionString;
con =新的SqlConnection(strConn);
con.Open();
如果(Session ["cmpny"]!= null)
hdcompany.Value =会话["cmpny"].ToString();
this.rptDoc = new ReportDocument();
如果(Session ["vchbill"]!= null)
hdbill.Value =会话["vchbill"].ToString();
如果(Session ["date"]!= null)
date.Value =会话["date"].ToString();
如果(Session ["party"]!= null)
hdparty.Value =会话["party"].ToString();


字符串查询=从salebillreport中选择*,其中vch =''" + hdbill.Value +''和companyname =""+ hdcompany.Value +"'';
//在查询中salebillreport是视图名称,hdbill.value和hdcompany.value是隐藏字段,这里的值是通过会话传来的.
con =新的SqlConnection(strConn);
SqlCommand com =新的SqlCommand(query,con);
com.CommandType = CommandType.Text;
SqlDataAdapter da =新的SqlDataAdapter(com);
da.Fill(ds,"salebillreport");
rptDoc.Load(Server.MapPath("saleitembillreport.rpt")));
rptDoc.SetDataSource(ds);
//参数传递
DateTime fromdate = Convert.ToDateTime(date.Value);
rptDoc.SetParameterValue("date",fromdate);
rptDoc.SetParameterValue("party",hdparty.Value);
rptDoc.SetParameterValue("company",hdcompany.Value);
rptDoc.SetParameterValue("bill",hdbill.Value);
////此代码用于在选择即刷新报告后清除报告
CrystalReportViewer1.ParameterFieldInfo.Clear();
CrystalReportViewer1.ReportSource = rptDoc;

}


谢谢,如果您喜欢这个,请投票给我
编码愉快





and then i execute query and save view and then in dataset i add tableadapter and then choose view tab and then select my view table.

And after that i create crystal report and i call dataset and select view table

and in c# i use these lines of code
public partial class saleitemvoucherbill : System.Web.UI.Page
{
string strConn;
SqlConnection con = new SqlConnection();
SqlCommand cmd = new SqlCommand();
DataSet ds = new DataSet("salereport");
private ReportDocument rptDoc = null;
protected void Page_Load(object sender, EventArgs e)
{
strConn = ConfigurationManager.ConnectionStrings["ConnectionASPX"].ConnectionString;
con = new SqlConnection(strConn);
con.Open();
if (Session["cmpny"] != null)
hdcompany.Value = Session["cmpny"].ToString();
this.rptDoc = new ReportDocument();
if (Session["vchbill"] != null)
hdbill.Value = Session["vchbill"].ToString();
if (Session["date"] != null)
date.Value = Session["date"].ToString();
if (Session["party"] != null)
hdparty.Value = Session["party"].ToString();


string query = " select * from salebillreport where vch=''"+hdbill.Value +"'' and companyname=''"+hdcompany.Value +"''" ;
// in query salebillreport is view name and hdbill.value and hdcompany.value are hiddenfields and here values are coming through sessions
con = new SqlConnection(strConn);
SqlCommand com = new SqlCommand(query, con);
com.CommandType = CommandType.Text;
SqlDataAdapter da = new SqlDataAdapter(com);
da.Fill(ds,"salebillreport");
rptDoc.Load(Server.MapPath("saleitembillreport.rpt"));
rptDoc.SetDataSource(ds);
//parameter pass
DateTime fromdate = Convert.ToDateTime(date.Value);
rptDoc.SetParameterValue("date", fromdate);
rptDoc.SetParameterValue("party", hdparty.Value);
rptDoc.SetParameterValue("company", hdcompany.Value);
rptDoc.SetParameterValue("bill", hdbill.Value);
//// this code is used for clear the report after selection means refreshing the report
CrystalReportViewer1.ParameterFieldInfo.Clear();
CrystalReportViewer1.ReportSource = rptDoc;

}


Thank you if You like this please vote for me
Happy coding


这篇关于如何使用asp.net中的一个数据集绑定来自多个数据表的Crystal Report C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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