ADO.Net
Why we can not create the object of DataReader class?
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Jul 19, 2014, 8:18 AM EDT
Vikram AgrawalRank #4,713 · 329 reputationPosted Jul 20, 2014, 7:10 AM EDT
when we create the object of SqlDataReader then its shows an compile time error that SqlDataReader class doesnt have any constructor in it.
and when we go to the meta data file of SqlDataReader there is no constructor presents in it.
Jignesh TrivediRank #16 · 50.3K reputationPosted Jul 20, 2014, 8:56 PM EDT
The SqlCommand.ExecuteReader() method returns an instance of the SqlDataReader class.data rows would be assigned to the cmd.ExecuteReader and it's previous assignment to an empty SqlReader would be pointless. Furthermore, the cmd.ExecuteReader() works as a factory method creating the SqlDataReader instance. we can't go about using the new keywords as SqlDataReader and also doesn't have a public constructor defined for SqlReader class.
hope this will help you.