Your ordign is wrong, and you are trying to reuse the same connection across multiple readers.
If you open a DataReader on a DataConnection, you cannot reuse the same connection object until the reader has been closed because teh SQL Engine will reject the request as it doesn't "know" that you are finished with the previous action.
For that reason (and a few others) it is a very good idea to use
using
blocks around all DB activities to ensure that itmes are clodes and dis0posed when you are finished with them:
using (SqlConnection con = new SqlConnection(strConnect))
{
con.Open();
using (SqlCommand cmd = new SqlCommand("SELECT Age, Description FROM myTable WHERE ID = @ID", con))
{
cmd.Parameters.AddWithValue("@ID", myTextBox.Text);
using (SqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
int age = (int) reader["Age"];
string desc = (string) reader["Description"];
Console.WriteLine($"{age}\n{desc}");
}
}
}
}
In this case, I'd suggest using a DataAdapter instead of a DataReader:
using (SqlConnection con = new SqlConnection(strConnect))
{
con.Open();
using (SqlDataAdapter da = new SqlDataAdapter("SELECT MyColumn1, MyColumn2 FROM myTable WHERE mySearchColumn = @SEARCH", con))
{
da.SelectCommand.Parameters.AddWithValue("@SEARCH", myTextBox.Text);
DataTable dt = new DataTable();
da.Fill(dt);
myDataGridView.DataSource = dt;
}
}