<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://forums.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Getting Started</title><link>http://forums.asp.net/15.aspx</link><description>The perfect forum for ASP.NET novices. No question too simple! &lt;A href="http://aspadvice.com/SignUp/list.aspx?l=21&amp;amp;c=17" target=_blank&gt;Email List&lt;/A&gt;</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>Re: when to use IDataReader  ? why not just read directly from datareader?</title><link>http://forums.asp.net/thread/2036940.aspx</link><pubDate>Sun, 02 Dec 2007 23:24:55 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2036940</guid><dc:creator>sahajMarg</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2036940.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=15&amp;PostID=2036940</wfw:commentRss><description>&lt;p&gt;benick thanks a lot for your answer...really.&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: when to use IDataReader  ? why not just read directly from datareader?</title><link>http://forums.asp.net/thread/2036931.aspx</link><pubDate>Sun, 02 Dec 2007 23:00:18 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2036931</guid><dc:creator>benrick</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2036931.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=15&amp;PostID=2036931</wfw:commentRss><description>&lt;p&gt;Well they are not exactly the same.The difference doesn&amp;#39;t have to do with the reader you&amp;#39;re using though. The difference between the two code blocks is that one is using a while loop and the other is a method. To make them the same they would look like these&lt;/p&gt;&lt;p&gt;&lt;b&gt;First Block&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;pre class="coloredcode"&gt;&lt;span class="kwd"&gt;protected void&lt;/span&gt; ReadReader(SqlDataReader rdr)
{
	&lt;span class="kwd"&gt;while&lt;/span&gt; (rdr.Read())
	{
		&lt;span class="cmt"&gt;// get the results of each column&lt;/span&gt;
		&lt;span class="kwd"&gt;string&lt;/span&gt; contact =   (&lt;span class="kwd"&gt;string&lt;/span&gt;)rdr[&lt;span class="st"&gt;&amp;quot;ContactName&amp;quot;&lt;/span&gt;];
		&lt;span class="kwd"&gt;string&lt;/span&gt; company = (&lt;span class="kwd"&gt;string&lt;/span&gt;)rdr[&lt;span class="st"&gt;&amp;quot;CompanyName&amp;quot;&lt;/span&gt;];
	}
}&lt;/pre&gt;&amp;nbsp;&lt;p&gt;&lt;b&gt;Second Block&lt;/b&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;pre class="coloredcode"&gt;&lt;span class="kwd"&gt;protected void&lt;/span&gt; ReadReader(IDataReader rdr)
{
	&lt;span class="kwd"&gt;while&lt;/span&gt; (rdr.Read())
	{
		&lt;span class="cmt"&gt;// get the results of each column&lt;/span&gt;
		&lt;span class="kwd"&gt;string&lt;/span&gt; contact =   (&lt;span class="kwd"&gt;string&lt;/span&gt;)rdr[&lt;span class="st"&gt;&amp;quot;ContactName&amp;quot;&lt;/span&gt;];
		&lt;span class="kwd"&gt;string&lt;/span&gt; company = (&lt;span class="kwd"&gt;string&lt;/span&gt;)rdr[&lt;span class="st"&gt;&amp;quot;CompanyName&amp;quot;&lt;/span&gt;];
	}
}&lt;/pre&gt;&amp;nbsp;&lt;p&gt;I like the second block better simply because you call them both using the same code, but the second one is not forcing you to continue using the SqlDataReader. It will allow you to change later on. You call the functions using the following code.&lt;br /&gt;&lt;/p&gt;&lt;pre class="coloredcode"&gt;ReadReader(myReader);&lt;/pre&gt;&lt;pre class="coloredcode"&gt;My reader could either be a SqlDataReader or an IDataReader of any kind for that matter.&amp;nbsp;&lt;/pre&gt;&lt;p&gt;I hope that makes sense,&lt;br /&gt;Brendan&lt;br /&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: when to use IDataReader  ? why not just read directly from datareader?</title><link>http://forums.asp.net/thread/2036322.aspx</link><pubDate>Sat, 01 Dec 2007 23:13:51 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2036322</guid><dc:creator>sahajMarg</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2036322.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=15&amp;PostID=2036322</wfw:commentRss><description>&lt;p&gt;&amp;nbsp;thanks, so that means that the following two blocs are exactly doing the same thing right?&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;pre&gt;&lt;font color="blue"&gt;while&lt;/font&gt; (rdr.Read())&lt;br /&gt;	{&lt;br /&gt;		&lt;font color="green"&gt;// get the results of each column&lt;/font&gt;&lt;br /&gt;		&lt;font color="blue"&gt;string&lt;/font&gt; contact =   (&lt;font color="blue"&gt;string&lt;/font&gt;)rdr[&amp;quot;ContactName&amp;quot;];&lt;br /&gt;		&lt;font color="blue"&gt;string&lt;/font&gt; company = (&lt;font color="blue"&gt;string&lt;/font&gt;)rdr[&amp;quot;CompanyName&amp;quot;];&lt;/pre&gt;&lt;pre&gt;	}&lt;/pre&gt;&lt;pre&gt;&lt;b&gt;Second Block&lt;/b&gt;&lt;/pre&gt;&lt;pre&gt;protected void ReadReader(IDataReader reader)&lt;/pre&gt;&lt;pre&gt;{&lt;/pre&gt;&lt;pre&gt;&lt;font color="blue"&gt;		string&lt;/font&gt; contact =   (&lt;font color="blue"&gt;string&lt;/font&gt;)rdr[&amp;quot;ContactName&amp;quot;];&lt;br /&gt;		&lt;font color="blue"&gt;string&lt;/font&gt; company = (&lt;font color="blue"&gt;string&lt;/font&gt;)rdr[&amp;quot;CompanyName&amp;quot;];&lt;br /&gt; &lt;br /&gt;&lt;/pre&gt;&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;} &lt;br /&gt;&lt;/pre&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: when to use IDataReader  ? why not just read directly from datareader?</title><link>http://forums.asp.net/thread/2036203.aspx</link><pubDate>Sat, 01 Dec 2007 19:13:39 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2036203</guid><dc:creator>benrick</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2036203.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=15&amp;PostID=2036203</wfw:commentRss><description>&lt;p&gt;This site has an interesting example of using an IDataReader interface for to look at machine processes. &lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.bearcanyon.com/dotnet/"&gt;http://www.bearcanyon.com/dotnet/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Here is a link to the sample download from that site &lt;a href="http://www.bearcanyon.com/dotnet/ProcessListReader.zip"&gt;http://www.bearcanyon.com/dotnet/ProcessListReader.zip&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Interfaces are very cool. For example SqlDataReader and XmlDataReader both implement the IDataReader interface. This means you might have a method called &lt;em&gt;DisplayUserData&lt;/em&gt; and the method takes an IDataReader as a parameter. It will not matter whether the datareader is a SqlDataReader or an XmlDataReader it will still be able to display the data correctly.&lt;/p&gt;
&lt;p&gt;Have a great day!&lt;/p&gt;
&lt;p&gt;Brendan&lt;/p&gt;</description></item><item><title>Re: when to use IDataReader  ? why not just read directly from datareader?</title><link>http://forums.asp.net/thread/2036148.aspx</link><pubDate>Sat, 01 Dec 2007 17:33:45 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2036148</guid><dc:creator>sahajMarg</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2036148.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=15&amp;PostID=2036148</wfw:commentRss><description>&lt;p&gt;thanks a lot for your reply. making sense now. Is it possible for you to give me a quick example of a custom class implementing IDataReader.&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: when to use IDataReader  ? why not just read directly from datareader?</title><link>http://forums.asp.net/thread/2036109.aspx</link><pubDate>Sat, 01 Dec 2007 16:29:40 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2036109</guid><dc:creator>benrick</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2036109.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=15&amp;PostID=2036109</wfw:commentRss><description>&lt;p&gt;The SqlDataReader you are talking about is a class which implements IDataReader. This means that anywhere an IDataReader may be used you can use SqlDataReader.&lt;/p&gt;</description></item><item><title>Re: when to use IDataReader  ? why not just read directly from datareader?</title><link>http://forums.asp.net/thread/2036107.aspx</link><pubDate>Sat, 01 Dec 2007 16:25:31 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2036107</guid><dc:creator>benrick</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2036107.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=15&amp;PostID=2036107</wfw:commentRss><description>&lt;p&gt;IDataReader is referring to an interface. Basically If your method accepts an IDataReader that means that it will accept anything that uses that interface. This means you can use any data reader you want basically. The method will accept your datareader because the datareader implements the IDataReader interface.&lt;/p&gt;
&lt;p&gt;The advantage of doing this is that the method is not specific to a specific type of data reader. You could also roll your own class that implements this interface.&lt;/p&gt;
&lt;p&gt;Basically an interface is just a set of stuff that needs to be implemented on anything using the interface.&amp;nbsp;To learn more read on there are plenty of sites on the internet which can explain Interfaces in C#.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/aa664574(vs.71).aspx"&gt;http://msdn2.microsoft.com/en-us/library/aa664574(vs.71).aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://www.csharp-station.com/Tutorials/Lesson13.aspx"&gt;http://www.csharp-station.com/Tutorials/Lesson13.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I hope that helps, &lt;br /&gt;Brendan&lt;/p&gt;</description></item><item><title>when to use IDataReader  ? why not just read directly from datareader?</title><link>http://forums.asp.net/thread/2036051.aspx</link><pubDate>Sat, 01 Dec 2007 15:05:26 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2036051</guid><dc:creator>sahajMarg</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2036051.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=15&amp;PostID=2036051</wfw:commentRss><description>&lt;p&gt;I might be confused. I have never used IDataReader to read through the datareader.&lt;/p&gt;&lt;p&gt;I normally do something like the following to read through a SqlDataReader.&lt;br /&gt;&lt;/p&gt;&lt;pre&gt;&lt;font color="blue"&gt;while&lt;/font&gt; (rdr.Read())&lt;br /&gt;	{&lt;br /&gt;		&lt;font color="green"&gt;// get the results of each column&lt;/font&gt;&lt;br /&gt;		&lt;font color="blue"&gt;string&lt;/font&gt; contact =   (&lt;font color="blue"&gt;string&lt;/font&gt;)rdr[&amp;quot;ContactName&amp;quot;];&lt;br /&gt;		&lt;font color="blue"&gt;string&lt;/font&gt; company = (&lt;font color="blue"&gt;string&lt;/font&gt;)rdr[&amp;quot;CompanyName&amp;quot;];&lt;/pre&gt;&lt;pre&gt;	}&lt;/pre&gt;&lt;pre&gt;My question is when do we do something like the following and what is the difference between the above and the below: Why to use IDataReader why not have ( SqlDataReader reader)?&lt;/pre&gt;&lt;pre&gt;protected void ReadReader(IDataReader reader)&lt;/pre&gt;&lt;pre&gt;{&lt;/pre&gt;&lt;pre&gt;&lt;font color="blue"&gt;		string&lt;/font&gt; contact =   (&lt;font color="blue"&gt;string&lt;/font&gt;)rdr[&amp;quot;ContactName&amp;quot;];&lt;br /&gt;		&lt;font color="blue"&gt;string&lt;/font&gt; company = (&lt;font color="blue"&gt;string&lt;/font&gt;)rdr[&amp;quot;CompanyName&amp;quot;];&lt;br /&gt; &lt;br /&gt;&lt;/pre&gt;&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;}&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item></channel></rss>