473,398 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Why not "new SqlDataReader()" ?


Why do I say:

SqlDataReader dr;

instead of

SqlDataReader dr = new SqlDataReader();

--
Texeme Textcasting Technology
http://texeme.com

Indie Pop Rocks @ SomaFM
http://somafm.com/

Nov 22 '05 #1
3 3249
This is because your SqlCommand object is going to return to you an instance
of SqlDataReader. You never create a datareader object yourself.

if you did the following you would have two SqlDataReader objects in memory.
and the first one would no longer have a reference to it.
SqlDataReader dr = new SqlDataReader();
dr = SqlCommand.ExecuteReader();

dr is the following case is basically a pointer. The SqlCommand return the
object that dr points to.
SqlDataReader dr

hope that clears it up for you.
Chris

"Ricola !" <se****************@tower.effeil> wrote in message
news:36*************@individual.net...

Why do I say:

SqlDataReader dr;

instead of

SqlDataReader dr = new SqlDataReader();

--
Texeme Textcasting Technology
http://texeme.com

Indie Pop Rocks @ SomaFM
http://somafm.com/

Nov 22 '05 #2
Ricola ! <se****************@tower.effeil> wrote:
Why do I say:

SqlDataReader dr;

instead of

SqlDataReader dr = new SqlDataReader();


There are no public constructors for SqlDataReader - if you could
construct one as above, what would you expect it to read?

You have to obtain a SqlDataReader reference from a call to a method of
another class - usually SqlCommand.ExecuteReader.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 22 '05 #3
Well .. if you did do ..

SqlDataReader dr = new SqlDataReader();

What resultset will your data reader be working upon?

- Sahil Malik
http://codebetter.com/blogs/sahil.malik/
"Ricola !" <se****************@tower.effeil> wrote in message
news:36*************@individual.net...

Why do I say:

SqlDataReader dr;

instead of

SqlDataReader dr = new SqlDataReader();

--
Texeme Textcasting Technology
http://texeme.com

Indie Pop Rocks @ SomaFM
http://somafm.com/

Nov 22 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Ricola ! | last post by:
Why do I say: SqlDataReader dr; instead of SqlDataReader dr = new SqlDataReader();
6
by: dpr | last post by:
I have come accross a piece of C++ code with the construct: MyClass *c = new class MyClass(); Is there a difference between this and: MyClass *c = new MyClass(); ?
6
by: peter.xiau | last post by:
I found that std::vector<int> v(10) ; will automatically initiallize every elem to 0 in the vector, I check the source code (VS.NET2003), and I found a line of code like this *T = new T() ; ...
37
by: jht5945 | last post by:
For example I wrote a function: function Func() { // do something } we can call it like: var obj = new Func(); // call it as a constructor or var result = Func(); // call it as...
30
by: Medvedev | last post by:
i see serveral source codes , and i found they almost only use "new" and "delete" keywords to make they object. Why should i do that , and as i know the object is going to be destroy by itself at...
0
by: jonceramic | last post by:
Hi All, My apologies for asking something that I'm sure has been answered for. But, my google searching can't find a proper set of keywords. I would like to add "New..." or "other..." or...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.