To create an instance of SqlDataReader class, you must call the ExecuteReader method of the SqlCommand object, instead of directly using a constructor.
//Error! Cannot use SqlDataReader() constructor
//to create an instance of SqlDataReader class
SqlDataReaderReaderObject = new SqlDataReader();
//Call the ExecuteReader method of the SqlCommand object
SqlCommandCommandObject = new SqlCommand();
SqlDataReaderReaderObject = CommandObject.ExecuteReader();
Creating an instance of SqlDataReader class using SqlDataReader() constructor generates a compile time error - The type 'System.Data.SqlClient.SqlDataReader' has no constructors defined.
//Error! Cannot use SqlDataReader() constructor
//to create an instance of SqlDataReader class
SqlDataReaderReaderObject = new SqlDataReader();
//Call the ExecuteReader method of the SqlCommand object
SqlCommandCommandObject = new SqlCommand();
SqlDataReaderReaderObject = CommandObject.ExecuteReader();
Creating an instance of SqlDataReader class using SqlDataReader() constructor generates a compile time error - The type 'System.Data.SqlClient.SqlDataReader' has no constructors defined.
No comments:
Post a Comment