C#

Moderators: None (Apply to moderate this forum)
Number of threads: 2722
Number of posts: 5749

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
c# ado.net Posted by rtz on 16 Dec 2012 at 7:13 AM
1. sqlconnection con = new sqlconnection();
2. con.connectionstring="connection string text";
3. string query="select *from dbo.names";
4. sqlcommand cmd = new sqlcommand(quey,con);
5. sqldatareader dr = cmd.excutereader();
6. while(dr.read())
7. {
8. console.writeline(dr["names"]);
9. }
10. con.close();

i am confused in line 5 where dr has the refrence to the method executereader() of the sqlcommand class.what is actually happening there when i am calling the read() of the sqldatareader class,can someone give me a detailed explanation on this.i am pretty new to c# and ado.net so i am a bit confused..pllz help.
Report
Re: c# ado.net Posted by Barnsite on 24 Dec 2012 at 3:04 AM
Hi,

sqldatareader dr = cmd.excutereader();

Okay, what's happening here is: you are copying the results of your sql command (cmd) into a data reader. In english, copy the select * from dbo.names into sqldatareader called dr.

The read() gets the next line from the datareader, or the first line the first time you call it. read() also returns false if there are no records left to read. Which is why you can do While(dr.read())

Good luck



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.