Reputation: 1043
I am getting a response from the select query and storing them in to the string list
string abc = "123";
List<string> numb = new List<string>();
string selectQuery = "SELECT Number FROM NumberList;";
using (MySqlConnection conn = new MySqlConnection(connStr))
using (MySqlCommand cmd = new MySqlCommand(selectQuery, conn))
{
conn.Open();
var reader = cmd.ExecuteReader();
while (reader.Read())
{
numb.Add(reader.GetString(0));
}
I am not sure how to check the string abc exists in numb. I dont want to use for loop for this because the count of records returned from query response is high. Is there any easy of checking if the 123 exists in the list or not.
Upvotes: 0
Views: 214
Reputation: 7115
while (reader.Read())
{
var s = reader.GetString(0);
if (!numb.Contains(s))
{
numb.Add(s);
}
}
Upvotes: 0
Reputation: 1455
This?
if (numb.Contains(abc))
{
// List contains the string contained in variable abc
}
Upvotes: 2