Hi
I am having a problem with the code below
Basically I want the matching records to be added to a listbox that exists on the same form as the textbox does. However, nothing appear in the textbox. The messagebox showing that the code has entered the while loop also does not appear... I am unsure whether it is my SQL statement that is wrong or not. Any help is much appreciateCode:private void surnameBox_Leave(object sender, EventArgs e) { string criteria = surnameBox.Text; try { SqlCommand filterAccounts = new SqlCommand ("SELECT * FROM Accounts WHERE Surname = @criteria", connectionLine); reader = filterAccounts.ExecuteReader(); while (reader.Read()) { MessageBox.Show("1"); filterBox.Items.Add(reader.GetString(3).ToString() + ", " + reader.GetString(4).ToString()); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } connectionLine.Close(); }![]()




Reply With Quote