The World’s Leading Microsoft .NET Magazine
   
 
EXCERPTS FROM THE FIELD

Search My Blog

 

Mailing List

My RSS Feeds








Don't forget Using and IDataReader

posted Monday, 29 October 2007

One of the things easily forgotten and under used is the "Using" statement. This is especially important when you have IDataReader implemented in your application as it doesn't always go away when you close it. Yes, you can adjust the connection to "Close" it, but I've found by creating your IDataReader with the Using statement, it goes away. No more running out of data readers.

 VB

Using dr As IDataReader = db.ExecuteReader("dbo.SomeProcedure", Params)

.... your code

End Using

C#

using (IDataReader rdr = cmd.ExecuteReader())
            {
                .... Your Code
            }

Very easy to implement and use.

 Happy Coding!!

tags:        

links: digg this    del.icio.us