I'm with rhaazy on this, except with one addition - make sure your
connection is still open when you pass it out.  For example:

public void DoSomethingWithReader(string sql)
{
  SqlDataReader reader = null;
  using (SqlConnection conn = {...})
  {
    using (SqlCommand comm = {...})
    {
      reader = comm.ExecuteReader();
      GetStuffFromReader(reader); // This one should be fine
    }
  }
  GetStuffFromReader(reader); // This one is not ok, since the
connection is disposed
}

On Sep 24, 2:50 am, Benj Nunez <[EMAIL PROTECTED]> wrote:
> Hello everyone,
>
> Just out of curiosity: Is it alright to pass a datareader object to a
> method or not?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web 
Services,.NET Remoting" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://cm.megasolutions.net/forums/default.aspx
-~----------~----~----~----~------~----~------~--~---

Reply via email to