I am dynamically creating a crystal report. When I run the program and click on a button, I get "Parameter is incorrect" information box. How can I resolve this?
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using MySql.Data.MySqlClient; using CrystalDecisions.CrystalReports.Engine; using CrystalDecisions.Shared; using CrystalDecisions.Windows.Forms; using System.Collections; namespace SupplyRequestAndInventoryManagementSystem { public partial class Report : Form { ReportDocument l = new ReportDocument(); connection con = new connection(); MySqlDataAdapter adapter; MySqlCommand cmd = new MySqlCommand(); MySqlDataReader reader; public Report() { InitializeComponent(); } private void Report_Load(object sender, EventArgs e) { } private void btnGenerate_Click(object sender, EventArgs e) { Hashtable hTable = new Hashtable(); ArrayList duplicateList = new ArrayList(); int column = 0; string c = "SELECT "; ParameterFields paramFields; ParameterField paramField; ParameterDiscreteValue paramDis; paramFields = new ParameterFields(); if (comboTable.SelectedIndex == 0) { //supplier if (checkBox1.Checked) { column++; c = c.Insert(c.Length, "Supp_SuppName as Column" + column.ToString()); paramField = new ParameterField(); paramField.Name = "col" + column.ToString(); paramDis = new ParameterDiscreteValue(); paramDis.Value = "Supplier"; paramField.CurrentValues.Add(paramDis); paramFields.Add(paramField); } //Name if (checkBox2.Checked) { column++; if (c.Contains("Column")) { c = c.Insert(c.Length, ","); } c = c.Insert(c.Length, "Supp_ProdName as Column" + column.ToString()); paramField = new ParameterField(); paramField.Name = "col" + column.ToString(); paramDis = new ParameterDiscreteValue(); paramDis.Value = "Name"; paramField.CurrentValues.Add(paramDis); paramFields.Add(paramField); } c += " FROM supply_record where Supply_type = 'Assets'"; crystalReportViewer1.ParameterFieldInfo = paramFields; con.Open(); MySqlDataAdapter sda = new MySqlDataAdapter(c, con.con); DataSet dat = new DataSet(); sda.Fill(dat, "supply_record"); l.Load("insert directory here"); l.SetDataSource(dat); crystalReportViewer1.ReportSource = l; con.Close(); for (int i = column; i < 2; i++) { column++; paramField = new ParameterField(); paramField.Name = "col" + column.ToString(); paramDis = new ParameterDiscreteValue(); paramDis.Value = ""; paramField.CurrentValues.Add(paramDis); paramFields.Add(paramField); } } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)