子报告参数未设置 [英] Sub report Parameter not set
本文介绍了子报告参数未设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的,
我有一个包含多个子报告的水晶报告。我想与c#联系。但是有一个问题是两个子报告链接没有得到。
我有4个用于查询的命令。所有都与一个主要命令链接。
i使用的主要代码如下:
Dear All,
I have one crystal report with multiple Subreport. and I want to link with the c#. but there is a problem that two sub report link is not getting.
I have 4 command used for query. and all are link with one main command.
i used the main code as below :
from_date12 = Request.QueryString["selected_date1"];
to_date12 = Request.QueryString["selected_date2"];
c.setcon();
string s = "select name from empl where id=''" + Session["user"].ToString() + "''";
SqlDataAdapter ad = new SqlDataAdapter(s, c.getcon());
DataSet ds = new DataSet();
ad.Fill(ds);
string s1 = "select * from munim002.dbo.sales_ctc where doj is not null and munim002.dbo.sales_ctc.refby=''" + ds.Tables[0].Rows[0][0].ToString() + "'' union select * from munim004.dbo.sales_ctc where doj is not null and munim004.dbo.sales_ctc.refby=''" + ds.Tables[0].Rows[0][0].ToString() + "'' union select * from munim005.dbo.sales_ctc where doj is not null and munim005.dbo.sales_ctc.refby=''" + ds.Tables[0].Rows[0][0].ToString() + "'' union select * from munim008.dbo.sales_ctc where doj is not null and munim008.dbo.sales_ctc.refby=''" + ds.Tables[0].Rows[0][0].ToString() + "'' union select * from munim017.dbo.sales_ctc where doj is not null and munim017.dbo.sales_ctc.refby=''" + ds.Tables[0].Rows[0][0].ToString() + "'' order by refby ";
SqlDataAdapter ad1 = new SqlDataAdapter(s1, c.getcon());
DataSet ds1 = new DataSet();
ad1.Fill(ds1);
string path = string.Empty;
path = Server.MapPath("REPORTS/sales ctc.rpt"); // load the report
cr = new ReportDocument();
cr.Load(path);
cr.SetDataSource(ds1.Tables[0]);
cr.SetParameterValue(0, ds1.Tables[0].Rows[0][0].ToString()); // set the parameter 1
cr.SetParameterValue(1, from_date12); //
cr.SetParameterValue(2, to_date12);
if (ds1.Tables[0].Rows.Count != 0)
{
string sub_report = "select * from munim002.dbo.sales_ctc1 where doj is not null and munim002.dbo.sales_ctc1.refby=''" + ds.Tables[0].Rows[0][0].ToString() + "'' union select * from munim004.dbo.sales_ctc1 where doj is not null and munim004.dbo.sales_ctc1.refby=''" + ds.Tables[0].Rows[0][0].ToString() + "'' union select * from munim005.dbo.sales_ctc1 where doj is not null and munim005.dbo.sales_ctc1.refby=''" + ds.Tables[0].Rows[0][0].ToString() + "'' union select * from munim008.dbo.sales_ctc1 where doj is not null and munim008.dbo.sales_ctc1.refby=''" + ds.Tables[0].Rows[0][0].ToString() + "'' union select * from munim017.dbo.sales_ctc1 where doj is not null and munim017.dbo.sales_ctc1.refby=''" + ds.Tables[0].Rows[0][0].ToString() + "''";
//string sub_report = "select * from munim002.dbo.sales_ctc1 where doj is not null union select * from munim004.dbo.sales_ctc1 where doj is not null union select * from munim005.dbo.sales_ctc1 where doj is not null union select * from munim008.dbo.sales_ctc1 where doj is not null union select * from munim017.dbo.sales_ctc1 where doj is not null ";
SqlDataAdapter sub_ad = new SqlDataAdapter(sub_report, c.getcon());
DataSet sub_ds = new DataSet();
sub_ad.Fill(sub_ds);
cr.Subreports["sales invoice.rpt - 01"].SetDataSource(sub_ds.Tables[0]);
for (int i = 0; i < sub_ds.Tables[0].Rows.Count; i++)
{
cr.SetParameterValue(0, sub_ds.Tables[0].Rows[i][1].ToString());
cr.SetParameterValue(1, from_date12);
cr.SetParameterValue(2, to_date12);
}
string sub_rep2 = "select * from munim002.dbo.sales_ctc2 where doj is not null union select * from munim004.dbo.sales_ctc2 where doj is not null union select * from munim005.dbo.sales_ctc2 where doj is not null union select * from munim008.dbo.sales_ctc2 where doj is not null union select * from munim017.dbo.sales_ctc2 where doj is not null order by refby ";
SqlDataAdapter sub_ad2 = new SqlDataAdapter(sub_rep2, c.getcon());
DataSet sub_ds2 = new DataSet();
sub_ad2.Fill(sub_ds2);
cr.Subreports["sales invoice.rpt - 02"].SetDataSource(sub_ds2.Tables[0]);
for (int j = 0; j < sub_ds2.Tables[0].Rows.Count; j++)
{
cr.SetParameterValue(0, sub_ds2.Tables[0].Rows[j][1].ToString());
cr.SetParameterValue(1, from_date12);
cr.SetParameterValue(2, to_date12);
}
string sub_report4 = " select * from munim002.dbo.sales_ctc3 where doj is not null union select * from munim004.dbo.sales_ctc3 where doj is not null union select * from munim005.dbo.sales_ctc3 where doj is not null union select * from munim008.dbo.sales_ctc3 where doj is not null union select * from munim017.dbo.sales_ctc3 where doj is not null order by refby";
SqlDataAdapter sub_ad4 = new SqlDataAdapter(sub_report4, c.getcon());
DataSet sub_ds4 = new DataSet();
sub_ad4.Fill(sub_ds4);
cr.Subreports["sales invoice.rpt - 03"].SetDataSource(sub_ds4.Tables[0]);
for (int i = 0; i < sub_ds4.Tables[0].Rows.Count; i++)
{
cr.SetParameterValue(0, sub_ds4.Tables[0].Rows[i][1].ToString());
cr.SetParameterValue(1, from_date12);
cr.SetParameterValue(2, to_date12);
}
// here one
//string sub_rep3 = "select * from munim002.dbo.se_exp_qry where munim002.dbo.se_exp_qry.prtname=''" + ds.Tables[0].Rows[0][0].ToString() + "'' union all select * from munim004.dbo.se_exp_qry where munim004.dbo.se_exp_qry.prtname=''" + ds.Tables[0].Rows[0][0].ToString() + "'' union all select * from munim005.dbo.se_exp_qry where munim005.dbo.se_exp_qry.prtname=''" + ds.Tables[0].Rows[0][0].ToString() + "'' union all select * from munim008.dbo.se_exp_qry where munim008.dbo.se_exp_qry.prtname=''" + ds.Tables[0].Rows[0][0].ToString() + "'' union all select * from munim017.dbo.se_exp_qry where munim017.dbo.se_exp_qry.prtname=''" + ds.Tables[0].Rows[0][0].ToString() + "'' ";
string sub_rep3 = "select * from munim002.dbo.se_exp_qry union all select * from munim003.dbo.se_exp_qry union all select * from munim005.dbo.se_exp_qry union all select * from munim008.dbo.se_exp_qry union all select * from munim017.dbo.se_exp_qry";
SqlDataAdapter sub_ad3 = new SqlDataAdapter(sub_rep3, c.getcon());
DataSet sub_ds3 = new DataSet();
sub_ad3.Fill(sub_ds3);
cr.Subreports["sales expense.rpt"].SetDataSource(sub_ds3.Tables[0]);
cr.SetParameterValue(0, ds1.Tables[0].Rows[0][0].ToString());
cr.SetParameterValue(1, from_date12);
cr.SetParameterValue(2, to_date12);
string sub_report5 = "select * from munim002.dbo.se_exp_qry where munim002.dbo.se_exp_qry.prtname=''" + ds.Tables[0].Rows[0][0].ToString() + "'' union all select * from munim004.dbo.se_exp_qry where munim004.dbo.se_exp_qry.prtname=''" + ds.Tables[0].Rows[0][0].ToString() + "'' union all select * from munim005.dbo.se_exp_qry where munim005.dbo.se_exp_qry.prtname=''" + ds.Tables[0].Rows[0][0].ToString() + "'' union all select * from munim008.dbo.se_exp_qry where munim008.dbo.se_exp_qry.prtname=''" + ds.Tables[0].Rows[0][0].ToString() + "'' union all select * from munim017.dbo.se_exp_qry where munim017.dbo.se_exp_qry.prtname=''" + ds.Tables[0].Rows[0][0].ToString() + "'' ";
SqlDataAdapter sub_ad5 = new SqlDataAdapter(sub_report5, c.getcon());
DataSet sub_ds5 = new DataSet();
sub_ad5.Fill(sub_ds5);
cr.Subreports["sales expense.rpt - 01"].SetDataSource(sub_ds5.Tables[0]);
for (int i = 0; i < sub_ds5.Tables[0].Rows.Count; i++)
{
string wq = sub_ds.Tables[0].Rows[i][1].ToString();
cr.SetParameterValue(0, wq);
cr.SetParameterValue(1, from_date12);
cr.SetParameterValue(2, to_date12);
}
string qry_pyrl = "SELECT PL_EMPCD, PL_EMPNAME, PL_MONTH, PL_YEAR, PL_TOTALPAY FROM MUNIM002.DBO.PAYROLLGEN UNION ALL SELECT PL_EMPCD, PL_EMPNAME, PL_MONTH, PL_YEAR, PL_TOTALPAY FROM MUNIM004.DBO.PAYROLLGEN UNION ALL SELECT PL_EMPCD, PL_EMPNAME, PL_MONTH, PL_YEAR, PL_TOTALPAY FROM MUNIM005.DBO.PAYROLLGEN UNION ALL SELECT PL_EMPCD, PL_EMPNAME, PL_MONTH, PL_YEAR, PL_TOTALPAY FROM MUNIM008.DBO.PAYROLLGEN UNION ALL SELECT PL_EMPCD, PL_EMPNAME, PL_MONTH, PL_YEAR, PL_TOTALPAY FROM MUNIM017.DBO.PAYROLLGEN";
SqlDataAdapter ad_qry = new SqlDataAdapter(qry_pyrl, c.getcon());
DataSet ds_qry = new DataSet();
ad_qry.Fill(ds_qry);
cr.Subreports["sales payroll.rpt - 01"].SetDataSource(ds_qry.Tables[0]);
cr.SetParameterValue(0, sub_ds2.Tables[0].Rows[0][0].ToString());
cr.SetParameterValue(1, from_date12);
cr.SetParameterValue(2, to_date12);
CrystalReportViewer1.ReportSource = cr;
CrystalReportViewer1.DataBind();
}
对此有任何帮助。
提前致谢。
Mitesh
any help for this.
Thanks in advance.
Mitesh
推荐答案
如果参数有value NULL将其设置为DBNull.Value。 NULL值参数不会发送到DBNull.Value发送到数据库的数据库。
if a Parameter has the value NULL set it to DBNull.Value. A NULL valued parameter is not send to the database where a DBNull.Value is send to the database.
这篇关于子报告参数未设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文