c# ado.net - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

c# ado.net

rtzrtz Posts: 1Member
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.


  • BarnsiteBarnsite Posts: 4Member

    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
Sign In or Register to comment.