I am attempting to tackle a project where I am pulling a column of data from an SQL database and comparing the data with values within a listbox. So far, it is finding a comparison, but is only returning one value, even with multiple matches in the listbox.
What am I doing wrong here? Thanks for any help anyone can offer.
private void btnDoAudit_Click(object sender, EventArgs e)
{
string respName = "something";
SqlDataReader reader = null;
using (SqlConnection conn = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=XXXX;Integrated Security=True;;User Instance=True"))
{
using (SqlCommand command = new SqlCommand("SELECT [Responsibility_Name] FROM [tblResponsibility] WHERE [Sensitive_Transaction]='TRUE'", conn))
{
conn.Open();
reader = command.ExecuteReader();
while (reader.Read())
{
respName = (string)reader["Responsibility_Name"];
if (lstResponsibilities.Items.Contains(respName) == true)
{
txtResults.Text = respName;
}
}
reader.Close();
conn.Close();
}
}
}