Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I've been having some problems executing this query in SQLite in C# - Visual Studio 2008. I have 2 comboboxes, the second one depends on the value selected in the first one (i.e: Province --> valid City for that province). I've searched the forums but I haven't figured out why this particular query returns 0 results. Am I setting the parameters correctly? Any suggestions will be greatly appreciated since I'm new at this. Thanks!

string provName = this.comboProvDest.GetItemText(this.comboDestProv.SelectedItem);
string queryDestCity = "SELECT d_city FROM Cities WHERE id_prov = @provName ";

SQLiteCommand cmCity = new SQLiteCommand(queryDestCity, conn);
cmCity.Parameters.AddWithValue("@provName", provName );
SQLiteDataReader drCity = cmCity.ExecuteReader();

 comboDestProv.Items.Add("");

 while (drCity.Read())
 {
      comboDestCity.Items.Add(drCity["d_city"].ToString());
      this.comboDestCity.DropDownStyle = ComboBoxStyle.DropDownList;
 }
share|improve this question
    
Did you try removing the space in "@provName " from cmCity.Parameters.AddWithValue("@provName ", provName );? –  unlimit Jun 4 '13 at 2:12
    
yeah it's just a typo in the code i posted since i had go translate it. thanks though! –  Juan M Jun 4 '13 at 3:15
    
You have already checked that data exists for the provname? –  unlimit Jun 4 '13 at 4:12
    
yes, there is data in a Province table, which populates the first combobox –  Juan M Jun 4 '13 at 20:16

1 Answer 1

  1. Put "this.comboDestCity.DropDownStyle = ComboBoxStyle.DropDownList;" after the "while..." loop
  2. Add "this.comboDestCity.Items.Clear()" before the loop
  3. Add "this.comboDestCity.Refresh" after the loop
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.