![](/img/trans.png)
[英]How to pass data from a textbox to a label in the same webform in c#?
[英]How do i pass parameter to subreports in crystal report from textbox c# webform
來自Appdev的問候(我是Crystall Report的新手)
我正在創建一個Web應用程序,其中將包含一個水晶報表。
我的要求是:
報告應基於文本框中提供的值(Web表單中的文本框)顯示。
例如:如果“文本框”值= 2,則僅顯示ID為2的項目。
我的水晶報表有3個子報表,例如cheque,Party(其中還包含來自其他表的值,稱為voucher),最后是bank。 這4個表由1個稱為id的公共字段鏈接。
這是我如何使用c#中的.cs文件中的參數綁定Crystal報表
public void LoadTransReceipt()
{
string Date = "";
string Sql = "SELECT tREC_NUPKId as ID from TB_TransReceipt where tREC_VCVoucherNo='" + TXTVou.Text.Trim() + "' and tREC_NUIsActive=1";
SqlDataReader rdr = mobjGenlib.objDBLib.ExecuteQueryReader(Sql.ToString());
while (rdr.Read())
{
Session["ID"] = rdr.GetValue(0).ToString();
}
rdr.Close();
if (!string.IsNullOrEmpty(Session["ID"] as string))
{
if (Session["Date"] != null)
{
Date = mobjGenlib.ConvertString(Session["Date"]);
}
reportPath = GetReportPath("ReceiptReport.rpt");
CRReport = new ReportDocument();
CRReport.Load(reportPath);
CrystalReportViewer1.ReportSource = CRReport;
AddParameterToReport("IDP", Session["ID"].ToString());
AddParameterToReport("ActiveP", 1);
AddParameterToReport("IDB", Session["ID"].ToString());
AddParameterToReport("ActiveB", 1);
AddParameterToReport("IDC", Session["ID"].ToString());
AddParameterToReport("ActiveC", 1);
// ConnectionInfo connectionInfo = ConnInfo();
ConnectionInfo objConnInfo = new ConnectionInfo();
objConnInfo.DatabaseName = "Demo";
objConnInfo.UserID = "aa";
objConnInfo.Password = "aaaa";
objConnInfo.ServerName = "HOME-PC\\SQLEXPRESS";
SetDBLogonForReport(objConnInfo, CRReport);
SetDataSetForMultipleSubReport(objConnInfo, CRReport);
}
}
但是當我執行代碼時,它會以兩倍的時間在表中顯示所有數據,如下所示
誰能幫我解決這個問題
提前致謝
作為錯誤
**
指定的參數超出有效值范圍
**”
在報表的“字段資源管理器”中,右鍵單擊添加新參數,然后在后面的代碼中必須設置參數的值,例如:
CRReport.SetParameterValue("@Parameter", TXTVou.Text)
您可以通過在查詢中添加單詞DISTINCT來防止重復,例如:
"SELECT DISTINCT tREC_NUPKId as ID from TB_TransReceipt where tREC_VCVoucherNo='" + TXTVou.Text + "' and tREC_NUIsActive=1"
或您可以通過字段中的(如果重復則抑制)屬性來防止重復
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.