Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Q) I heard in some video that 'SqlDataReader' class does not have any constructor. Is it true ?
As far as my knowledge there is no class can have zero constructors. If I don not write
declare any constructor in a class then C# compiler will add default constructor to the class.

Q)If my Code is like
SqlDataReader dr;
Some people are saying that dr is object.
Is it a Object or Reference Variable ?
Posted

You can check MSDN documentation - http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader%28v=vs.110%29.aspx[^].
According to this - "To create a SqlDataReader, you must call the ExecuteReader method of the SqlCommand object, instead of directly using a constructor."

dr is a variable that holds a pointer to an object.
A ref is different - http://msdn.microsoft.com/en-us/library/14akc2c7.aspx[^].
 
Share this answer
 
1. The constructor is not exposed, that is not publicly available:
To create a SqlDataReader, you must call the ExecuteReader method of the SqlCommand object, instead of directly using a constructor.


2. dr is a reference variable. After the
SqlDatareader dr

statement, dr is equal to null.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900