Nel

Nel

  • NA
  • 716
  • 1.1m

Error message "No value given for one or more required parameters"-Crystal Reports using dataset

Nov 15 2011 2:39 AM
Hi,

I have a Crystal Report and I use dataset and OleDbDataAdapter to get the values that the user chose on the form.
Here is my code:
ReportDocument cryRpt = new ReportDocument();
 
  string comstring = "SELECT NOVI.GBR, NOVI.AB, NALOG1.DATA,Min(NALOG1.POCKM) AS MinOfPOCKM,Max(NALOG1.KRAJKM) AS MaxOfKRAJKM,(Max(NALOG1.KRAJKM)-Min(NALOG1.POCKM)) AS RAZLIKA FROM (NALOG1 INNER JOIN MAGACIN ON NALOG1.GBRV=MAGACIN.GBR) INNER JOIN NOVI ON NALOG1.GBRV=NOVI.GBR where (  ( (NOVI.GBR)>='?' And (NOVI.GBR)<='?' ) AND ( (NOVI.AB)='?'  or  (NOVI.AB)='?'  )  AND  ( ( (NALOG1.DATA)>=?) and ((NALOG1.DATA)<=?) )  ) GROUP BY NOVI.GBR, NOVI.AB, NALOG1.DATA";
 
  OleDbCommand command = new OleDbCommand();
  command.Connection = conn;
  command.CommandText = comstring;
  if (radioButton4.Checked==true){
  command.Parameters.AddWithValue("@gbr1", textBox1.Text);
  command.Parameters.AddWithValue("@gbr2", textBox1.Text);
  }
  if (radioButton5.Checked==true){
 
  command.Parameters.AddWithValue("@gbr1", "1001");
  command.Parameters.AddWithValue("@gbr2", "1080");
  }
  if (radioButton6.Checked==true){
 
  command.Parameters.AddWithValue("@gbr1","1081" );
  command.Parameters.AddWithValue("@gbr2", "1149");
  }
  if (radioButton7.Checked == true)
  {
  command.Parameters.AddWithValue("@gbr1", "1001");
  command.Parameters.AddWithValue("@gbr2", "1149");
  }
  if(checkBox1.Checked==true){
  command.Parameters.AddWithValue("@ab1", 1);
  command.Parameters.AddWithValue("@ab2", 1);
  }
  else if (checkBox2.Checked==true)
  {
  command.Parameters.AddWithValue("@ab1", 2);
  command.Parameters.AddWithValue("@ab2", 2);
  }
  else if((checkBox1.Checked==true) && (checkBox2.Checked==true))
  {
  command.Parameters.AddWithValue("@ab", 1);
  command.Parameters.AddWithValue("@ab",2);
  }
  command.Parameters.AddWithValue("@data1", dateTimePicker1.Value);
  command.Parameters.AddWithValue("@data2", dateTimePicker2.Value);
  DataSet dataSet2=new DataSet(); 
  conn.Open();
 
  OleDbDataAdapter oleDBDataAdapter1 = new OleDbDataAdapter(new OleDbCommand(comstring, conn));
  OleDbCommand command1 = new OleDbCommand();
  command1.Connection = conn;
  oleDBDataAdapter1.SelectCommand.CommandText=comstring;
  dataSet2.Clear();
  oleDBDataAdapter1.Fill(dataSet2);
 
  cryRpt.SetDataSource(dataSet2);
  crystalReportViewer1.DisplayToolbar=true;
 
  cryRpt.Load(@"E:\Potrosuvacka-Pregledi\Potrosuvacka-Pregledi\CrystalReport1.rpt");
 
  crystalReportViewer1.ReportSource = cryRpt;
 
  cryRpt.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.Landscape;
  crystalReportViewer1.Refresh();
  conn.Close();

System.Data.OleDb.OleDbException was unhandled
  Message="No value given for one or more required parameters."

Could anybody help me please?
Thanks in advance
 

Answers (3)