My understanding of the DataReader object is that you don't create a new instance of it, like this:
Code:
SqlDataReader myReader = new SqlDataReader();
This will give you the error, "'System.Data.SqlClient.SqlDataReader' has no constructors defined".
Instead, you assign an instance of the DataReader object to a SqlCommand command:
Code:
string strConnectionString = ConfigurationManager.ConnectionStrings["SqlConnectionString"].ConnectionString;
SqlConnection myConnection = new SqlConnection();
myConnection.ConnectionString = strConnectionString;
string strCommandText = "SELECT FirstName, LastName FROM Users;
SqlCommand myCommand = new SqlCommand(strCommandText, myConnection);
myConnection.Open();
SqlDataReader myReader = myCommand.ExecuteReader(); // <-- *** Here is the instantiation
while (myReader.Read())
{
// process the rows in myReader using
// Convert.ToString(myReader["FirstName"]) and
// Convert.ToString(myReader["LastName"])
}
myReader.Close();