Howdy, Stranger!





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(
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 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(

    Good luck
Sign In or Register to comment.