Luke Baker

Luke Baker

  • NA
  • 20
  • 21.7k

Error : Must declare the scalar variable

Mar 30 2012 4:04 PM
Right im a junior programmer and im trying to build a system which shows data from a database. I have about 18 check boxes will all different types of data. Depending on what is ticked will depend on what is displayed in the data grid. Im having to use sql parameters in my SQL statement. Below is the code im using in my function which is called in each of the checkboxes checked changed methods aswell. The current error is Must Declare the scalar variable Filter0 Below is the function -
strQualified is an array of strings and paramArray is an array of sqlParameter
much help is needed :-)
[code]
private void chkBoxFilter()         {                         if (chkBlood.Checked)                 strQualified[0] = "BloodTransfusion1";             else                 strQualified[0] = "";             if (chBlood2.Checked)                 strQualified[1] = "BloodTransfusion2";             else                 strQualified[1] = "";             if (chkDementia.Checked)                 strQualified[2] = "Dementia";             else                 strQualified[2] = "";             if (chkEpidural.Checked)                 strQualified[3] = "Epidural";             else                 strQualified[3] = "";             if (chkEqualityDiversity.Checked)                 strQualified[4] = "EqualityDiversity";             else                 strQualified[4] = "";             if (chkInfectionControl.Checked)                 strQualified[5] = "InfectionControl";             else                 strQualified[5] = "";             if (chkInformationGovernance.Checked)                 strQualified[6] = "InformationGovern";             else                 strQualified[6] = "";             if (chkInsulin.Checked)                 strQualified[7] = "Insulin";             else                 strQualified[7] = "";             if (chkIV.Checked)                 strQualified[8] = "IV";             else                 strQualified[8] = "";             if (chkMandatoryA.Checked)                 strQualified[9] = "MandatoryA";             else                 strQualified[9] = "";             if (chkMandatoryB.Checked)                 strQualified[10] = "MandatoryB";             else                 strQualified[10] = "";             if (chkMandatoryC.Checked)                 strQualified[11] = "MandatoryC";             else                 strQualified[11] = "";             if (chkManualHandling.Checked)                 strQualified[12] = "ManualHandling";             else                 strQualified[12] = "";             if (chkMedicine.Checked)                 strQualified[13] = "MedicineManagement";             else                 strQualified[13] = "";             if (chkMentorsUpdate.Checked)                 strQualified[14] = "MentorsUpdate";             else                 strQualified[14] = "";             if (chkPDR.Checked)                 strQualified[15] = "PDR";             else                 strQualified[15] = "";             if (chkPIN.Checked)                 strQualified[16] = "PIN";             else                 strQualified[16] = "";             if (chkSafeGuarding.Checked)                 strQualified[17] = "SafeGuardingAdults";             else                 strQualified[17] = "";             for(int i = 0; i < strQualified.Length;i++)     {         paramArray[i] = new SqlParameter();         paramArray[i].ParameterName = "@Filter" + i.ToString();         paramArray[i].Value = strQualified[i];              }             command = @"Select * from view_TrainingHist where training_Type = @Filter0 OR  training_Type = @Filter1 OR training_Type = @Filter2 OR training_Type = @Filter3 OR  training_Type = @Filter4 OR training_Type = @Filter5 OR training_Type = @Filter6 OR  training_Type = @Filter7 OR training_Type = @Filter8 OR training_Type = @Filter9 OR  training_Type = @Filter10 OR training_Type = @Filter11 OR training_Type = @Filter12 OR  training_Type = @Filter13 OR training_Type = @Filter14 OR training_Type = @Filter15 OR  training_Type = @Filter16 OR training_Type = @Filter17";             dc.GainConnection(command, dgv1, "view_TrainingHist");                 }

[/code]

Answers (4)