我正在使用Visual Studio 2008和SQL Server 2008,语言C#
我想将多个参数传递给ASP.NET中的Crystal Report。我有两个参数@accountnumber
和@customerid
。但我只能将一个参数传递给我的报告,如下面的代码所示。
CrystalReportViewer1.LogOnInfo[0].ConnectionInfo.ServerName = "CJ-PC";
CrystalReportViewer1.LogOnInfo[0].ConnectionInfo.UserID = "sa";
CrystalReportViewer1.LogOnInfo[0].ConnectionInfo.Password = "***";
CrystalReportViewer1.LogOnInfo[0].ConnectionInfo.DatabaseName = "Online";
string accountnumber = "acc001";
string customerID = "cus001";
ParameterField paramField = new ParameterField();
ParameterFields paramFields = new ParameterFields();
ParameterDiscreteValue paramDiscreteValue = new ParameterDiscreteValue();
paramField.Name = "@account_number";
paramDiscreteValue.Value = accountnumber;
paramField.CurrentValues.Add(paramDiscreteValue);
paramFields.Add(paramField);
CrystalReportViewer1.ParameterFieldInfo = paramFields;
ParameterField paramField1 = new ParameterField();
ParameterFields paramFields1 = new ParameterFields();
ParameterDiscreteValue paramDiscreteValue1 = new ParameterDiscreteValue();
paramField1.Name = "@account_number";
paramDiscreteValue1.Value = accountnumber;
paramField1.CurrentValues.Add(paramDiscreteValue1);
paramFields1.Add(paramField1);
paramField1.Name = "@customer_id";
paramDiscreteValue1.Value = customerID;
paramField1.CurrentValues.Add(paramDiscreteValue1);
paramFields1.Add(paramField1);
CrystalReportViewer1.ParameterFieldInfo = paramFields1;
答案 0 :(得分:1)
在为new
paramField1
关键字
paramField1.Name = "@account_number";
paramDiscreteValue1.Value = accountnumber;
paramField1.CurrentValues.Add(paramDiscreteValue1);
paramFields1.Add(paramField1);
//Here is the missing code
paramField1 = new ParameterField();
paramField1.Name = "@customer_id";
paramDiscreteValue1.Value = customerID;
paramField1.CurrentValues.Add(paramDiscreteValue1);
paramFields1.Add(paramField1);
答案 1 :(得分:0)
这就是我在代码中所做的
CrystalReportViewer1.RefreshReport();
String ssCustomer = Session["ssCustomer"].ToString();
string strconstring = ConfigurationManager.ConnectionStrings["ONLINE_BANKING2_ConnectionString"].ConnectionString;
string sqlquery2;
sqlquery2 = "SELECT [account_number],[customer_id] from customer_details where customer_id = '" + ssCustomer + "'";
SqlConnection mycon2 = new SqlConnection(strconstring);
SqlCommand cmd = new SqlCommand(sqlquery2, mycon2);
mycon2.Open();
SqlDataReader myreader = cmd.ExecuteReader();
myreader.Read();
string accountnumber = myreader["account_number"].ToString();
string customerID = myreader["customer_id"].ToString();
myreader.Close();
mycon2.Close();
ParameterDiscreteValue objDiscreteValue;
ParameterField objParameterField;
//specify all the database Login details
CrystalReportViewer1.LogOnInfo[0].ConnectionInfo.ServerName = "CJ-PC";
CrystalReportViewer1.LogOnInfo[0].ConnectionInfo.UserID = "sa";
CrystalReportViewer1.LogOnInfo[0].ConnectionInfo.Password = "123";
CrystalReportViewer1.LogOnInfo[0].ConnectionInfo.DatabaseName = "online_banking2";
//Set value for first parameter
objDiscreteValue = new ParameterDiscreteValue();
objDiscreteValue.Value = accountnumber;
objParameterField = CrystalReportViewer1.ParameterFieldInfo["@account_number"];
objParameterField.CurrentValues.Add(objDiscreteValue);
CrystalReportViewer1.ParameterFieldInfo.Add(objParameterField);
objParameterField = CrystalReportViewer1.ParameterFieldInfo["@customer_id"];
objDiscreteValue = new ParameterDiscreteValue();
objDiscreteValue.Value = customerID;
objParameterField.CurrentValues.Add(objDiscreteValue);
CrystalReportViewer1.ParameterFieldInfo.Add(objParameterField);
答案 2 :(得分:0)
如果上述代码对您没有帮助,请按照以下说明操作:
转到CrystalReportSource
属性 - > Report
属性 - > Paratemers
属性 - > Add new parameter
你去吧。您必须将参数命名为@account_number
并为其指定ControlID
答案 3 :(得分:0)
您可以按照以下方式将值传递给Crystal Reports中的各种参数。
@{ Layout = null; }
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
<!--All Required REACTJS Lib-->
</head>
<body>
<div id="container">
</div>
<script crossorigin src="https://cdnjs.cloudflare.com/ajax/libs/react/16.4.0/umd/react.development.js"></script>
<script crossorigin src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.4.0/umd/react-dom.development.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/remarkable/1.7.1/remarkable.min.js"></script>
<script type="module" src="@Url.Content(" ~/Scripts/react/myapp.jsx ")">
</script>
</body>
</html>