Click here to Skip to main content
16,021,112 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
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?


C#
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);

                }
            }
       }
    }
}


What I have tried:

Columns are ordered. For loop is ok. But still the error lingers.
Posted
Comments
CHill60 1-Mar-16 9:53am    
On which line do you get the error?
[no name] 1-Mar-16 10:09am    
Don't really have an error on the code. But when i press the generate button the crystal reports viewer gives a message box that tells me that the parameter is incorrect.
CHill60 1-Mar-16 10:12am    
That will be an error in the code then. Use the debugger to examine what you are passing into the report. Does the messagebox not give more detail than that?
[no name] 1-Mar-16 10:15am    
No not really. It just only tells me that the parameter is incorrect. hmm
Sinisa Hajnal 2-Mar-16 2:35am    
Set a breakpoint in the code and go through step by step. Check that each parameter has same name, case and type in the report and in the code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900