gpt4 book ai didi

c# - 为什么 Crystal 报表总是提示参数不正确?在c#中动态生成报表时?

转载 作者:太空宇宙 更新时间:2023-11-03 15:27:49 25 4
gpt4 key购买 nike

我正在开发一个动态的 Crystal 报告我添加了正确的permeters 即使我检查了它显示的 crystalreportviewer 上的 Paramfieldinfo 属性 5个参数加上名字就完美了。

但在创建参数时仍然显示“参数不正确” 选择 ListOfValues 选项是动态的。 我从 4 小时开始就解决了这个问题,我不知道它在哪里,你能告诉我吗 请谢谢。

我的代码是:

        string query = "SELECT ";
int columnNo = 0;

if (chbCode.Checked)
{
columnNo++;
query = query.Insert(query.Length, "Customer_Code as Column" +
columnNo.ToString());

paramField = new ParameterField();
paramField.Name = "col" + columnNo.ToString();
paramDiscreteValue = new ParameterDiscreteValue();
paramDiscreteValue.Value = "Customer Code";
paramField.CurrentValues.Add(paramDiscreteValue);
//Add the paramField to paramFields
paramFields.Add(paramField);
}
if (chbFirstName.Checked)
{
columnNo++;
if (query.Contains("Column"))
{
query = query.Insert(query.Length, ", ");
}
query = query.Insert(query.Length, "FirstName as Column" +
columnNo.ToString());

paramField = new ParameterField();
paramField.Name = "col" + columnNo.ToString();
paramDiscreteValue = new ParameterDiscreteValue();
paramDiscreteValue.Value = "First Name";
paramField.CurrentValues.Add(paramDiscreteValue);
//Add the paramField to paramFields
paramFields.Add(paramField);
}
if (chbLastName.Checked)
{
columnNo++; //To determine Column number
if (query.Contains("Column"))
{
query = query.Insert(query.Length, ", ");
}
query = query.Insert(query.Length, "LastName as Column" +
columnNo.ToString());

paramField = new ParameterField();
paramField.Name = "col" + columnNo.ToString();
paramDiscreteValue = new ParameterDiscreteValue();
paramDiscreteValue.Value = "Last Name";
paramField.CurrentValues.Add(paramDiscreteValue);
//Add the paramField to paramFields
paramFields.Add(paramField);
}
if (chbAddress.Checked)
{
columnNo++;
if (query.Contains("Column"))
{
query = query.Insert(query.Length, ", ");
}
query = query.Insert(query.Length, "Address as Column" +
columnNo.ToString());

paramField = new ParameterField();
paramField.Name = "col" + columnNo.ToString();
paramDiscreteValue = new ParameterDiscreteValue();
paramDiscreteValue.Value = "Address";
paramField.CurrentValues.Add(paramDiscreteValue);
//Add the paramField to paramFields
paramFields.Add(paramField);
}
if (chbPhone.Checked)
{
columnNo++;
if (query.Contains("Column"))
{
query = query.Insert(query.Length, ", ");
}
query = query.Insert(query.Length, "Phone as Column" +
columnNo.ToString());

paramField = new ParameterField();
paramField.Name = "col" + columnNo.ToString();
paramDiscreteValue = new ParameterDiscreteValue();
paramDiscreteValue.Value = "Phone";
paramField.CurrentValues.Add(paramDiscreteValue);
//Add the paramField to paramFields
paramFields.Add(paramField);
}

//if there is any remaining parameter, assign empty value for that
//parameter.
for (int i = columnNo; i < 5; i++)
{
columnNo++;
paramField = new ParameterField();
paramField.Name = "col" + columnNo.ToString();
paramDiscreteValue = new ParameterDiscreteValue();
paramDiscreteValue.Value = "";
paramField.CurrentValues.Add(paramDiscreteValue);
//Add the paramField to paramFields
paramFields.Add(paramField);
}

crystalReportViewer1.ParameterFieldInfo = paramFields;

query += " FROM Customer";
return query;

请解决我的问题。谢谢

最佳答案

尝试像这样添加它:

CrystalReportSource1.ReportDocument.SetParameterValue(0, "ParameterValue");

关于c# - 为什么 Crystal 报表总是提示参数不正确?在c#中动态生成报表时?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34546010/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com