<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://codeforeternity.com/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>Cool Extension Methods for IDataReader Interface</title><link>http://codeforeternity.com/blogs/technology/archive/2008/04/15/cool-extension-methods-for-idatareader-interface.aspx</link><description>I find it really annoying to use the GetOrdinal method of the DataReader class everytime I have to access data in a strongly typed manner using any of the Get[DataType] methods of the DataReader class. Have a look at below code: int employeeID = dr.GetInt32</description><dc:language>en</dc:language><generator>CommunityServer 2007.1 (Build: 20917.1142)</generator><item><title>re: Cool Extension Methods for IDataReader Interface</title><link>http://codeforeternity.com/blogs/technology/archive/2008/04/15/cool-extension-methods-for-idatareader-interface.aspx#313</link><pubDate>Wed, 04 Feb 2009 09:08:36 GMT</pubDate><guid isPermaLink="false">6581de12-b79f-4db0-af9f-717dfd7c7876:313</guid><dc:creator>Assam</dc:creator><description>&lt;p&gt;I don't think this much number of methods is required. By the help of generics we can achieve the task. See the example below:&lt;/p&gt;
&lt;p&gt;public static T GetValue&amp;lt;T&amp;gt;(this IDataReader dr,string columnName) where T : IConvertible&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;T retValue;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;object obj = dr.GetValue(dr.GetOrdinal(columnName));&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if (obj != null)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;retValue = (T)Convert.ChangeType(obj, typeof(T));&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;return retValue;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;}&lt;/p&gt;
&lt;img src="http://codeforeternity.com/aggbug.aspx?PostID=313" width="1" height="1"&gt;</description></item><item><title>re: Cool Extension Methods for IDataReader Interface</title><link>http://codeforeternity.com/blogs/technology/archive/2008/04/15/cool-extension-methods-for-idatareader-interface.aspx#291</link><pubDate>Thu, 11 Dec 2008 04:51:57 GMT</pubDate><guid isPermaLink="false">6581de12-b79f-4db0-af9f-717dfd7c7876:291</guid><dc:creator>eKnacks</dc:creator><description>&lt;p&gt;You've been knacked. Keep up the good work.&lt;/p&gt;
&lt;img src="http://codeforeternity.com/aggbug.aspx?PostID=291" width="1" height="1"&gt;</description></item><item><title>re: Cool Extension Methods for IDataReader Interface</title><link>http://codeforeternity.com/blogs/technology/archive/2008/04/15/cool-extension-methods-for-idatareader-interface.aspx#232</link><pubDate>Tue, 24 Jun 2008 07:35:43 GMT</pubDate><guid isPermaLink="false">6581de12-b79f-4db0-af9f-717dfd7c7876:232</guid><dc:creator>Damon Carr</dc:creator><description>&lt;p&gt;The performance difference is irrelevant when compared to the total time. It is almost all out of process work.&lt;/p&gt;
&lt;p&gt;Also, you will typically gain far more net net when you have code &amp;nbsp;that might be slower (but noticably bad is the point) yet more readable.maintainable. &lt;/p&gt;
&lt;p&gt;Unless you are building real-time systems, server based multi-threaded transaction servers, etc. the entire 'general focus' on performance optimizations should not exist more times then not.&lt;/p&gt;
&lt;p&gt;Force yourself to optimize your code at the end of your iterations and see the large savings in time, reduction in often unnecessary code and overall bandwidth improvement, &lt;/p&gt;
&lt;p&gt;Kind Regards,&lt;/p&gt;
&lt;p&gt;Damon Wilder Carr&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://damon.agilefactor.com"&gt;http://damon.agilefactor.com&lt;/a&gt;&lt;/p&gt;
&lt;img src="http://codeforeternity.com/aggbug.aspx?PostID=232" width="1" height="1"&gt;</description></item><item><title>Benchmarking do dataReader.GetOrdinal() &amp;laquo; Programatik - O local do estagi??rio de Inform??tica</title><link>http://codeforeternity.com/blogs/technology/archive/2008/04/15/cool-extension-methods-for-idatareader-interface.aspx#176</link><pubDate>Mon, 12 May 2008 14:51:57 GMT</pubDate><guid isPermaLink="false">6581de12-b79f-4db0-af9f-717dfd7c7876:176</guid><dc:creator>Benchmarking do dataReader.GetOrdinal() « Programatik - O local do estagi??rio de Inform??tica</dc:creator><description>&lt;p&gt;Pingback from &amp;nbsp;Benchmarking do dataReader.GetOrdinal() &amp;amp;laquo; Programatik - O local do estagi??rio de Inform??tica&lt;/p&gt;
&lt;img src="http://codeforeternity.com/aggbug.aspx?PostID=176" width="1" height="1"&gt;</description></item><item><title>re: Cool Extension Methods for IDataReader Interface</title><link>http://codeforeternity.com/blogs/technology/archive/2008/04/15/cool-extension-methods-for-idatareader-interface.aspx#157</link><pubDate>Fri, 02 May 2008 14:02:44 GMT</pubDate><guid isPermaLink="false">6581de12-b79f-4db0-af9f-717dfd7c7876:157</guid><dc:creator>raj</dc:creator><description>&lt;p&gt;Hi Chris,&lt;/p&gt;
&lt;p&gt;Thanks for your excellent feedback. I have updated my post to point users to your comments. Appreciated :-)&lt;/p&gt;
&lt;p&gt;Cheers,&lt;br /&gt;Raj&lt;/p&gt;
&lt;p&gt;~~~ CODING FOR ETERNITY !!! ~~~&lt;/p&gt;&lt;img src="http://codeforeternity.com/aggbug.aspx?PostID=157" width="1" height="1"&gt;</description></item><item><title>re: Cool Extension Methods for IDataReader Interface</title><link>http://codeforeternity.com/blogs/technology/archive/2008/04/15/cool-extension-methods-for-idatareader-interface.aspx#156</link><pubDate>Thu, 01 May 2008 14:32:04 GMT</pubDate><guid isPermaLink="false">6581de12-b79f-4db0-af9f-717dfd7c7876:156</guid><dc:creator>Chris</dc:creator><description>&lt;p&gt;&amp;quot;Because ordinal-based lookups are more efficient than named lookups, it is inefficient to call GetOrdinal within a loop. Save time by calling GetOrdinal once and assigning the results to an integer variable for use within the loop.&amp;quot; &lt;a rel="nofollow" target="_new" href="http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldatareader.getordinal.aspx"&gt;msdn.microsoft.com/.../system.data.sqlclient.sqldatareader.getordinal.aspx&lt;/a&gt;&lt;/p&gt;
&lt;img src="http://codeforeternity.com/aggbug.aspx?PostID=156" width="1" height="1"&gt;</description></item><item><title>Cool Extension Methods for IDataReader Interface</title><link>http://codeforeternity.com/blogs/technology/archive/2008/04/15/cool-extension-methods-for-idatareader-interface.aspx#129</link><pubDate>Tue, 15 Apr 2008 22:55:09 GMT</pubDate><guid isPermaLink="false">6581de12-b79f-4db0-af9f-717dfd7c7876:129</guid><dc:creator>DotNetKicks.com</dc:creator><description>&lt;p&gt;You've been kicked (a good thing) - Trackback from DotNetKicks.com&lt;/p&gt;
&lt;img src="http://codeforeternity.com/aggbug.aspx?PostID=129" width="1" height="1"&gt;</description></item></channel></rss>