Entire error is quite self explanatory.
You are using SQLReader instance to read the data but have not opened up the connection with database to do so. Would recommend you to go through ADO.NET basics and then try again.
Regarding the data communication can be read here:
Accessing data with ADO.NET[
^]
MSDN: Retrieving Data Using a DataReader (ADO.NET)[
^]
MSDN: DataReader Class[
^]
Beginners guide to accessing SQL Server through C#[
^]
Sample:
using (connection)
{
SqlCommand command = new SqlCommand("SELECT CategoryID, CategoryName FROM Categories;", connection);
connection.Open();
SqlDataReader reader = command.ExecuteReader();
if (reader.HasRows)
{
while (reader.Read())
{
Console.WriteLine("{0}\t{1}", reader.GetInt32(0),
reader.GetString(1));
}
}
else
{
Console.WriteLine("No rows found.");
}
reader.Close();
}