Results 1 to 3 of 3

Thread: clearing datareader in memory?

  1. #1

    Thread Starter
    Fanatic Member popskie's Avatar
    Join Date
    Jul 2005
    Location
    In my chair
    Posts
    666

    clearing datareader in memory?

    SqlDataReader dreader = new SqlDataReader();
    ...
    ...
    ...
    how to clear the dreader instance in memory? Is it dreader.Close() or dreader = null.

    thanks in advance.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: clearing datareader in memory?

    You can't create an data reader using the "new" keyword as it has no public constructor, but assuming you have created one by calling ExecuteReader on a command, all you have to do is call Close on it. You can set the variable to null as well if you like, but that will have no real effect unless your variable remains in scope for some time after you've finished using the data reader. Setting the variable to null removes the reference to the object and thus makes it eligible for garbage collection, but that will happen as soon as the variable loses scope anyway, so if it is a local variable then setting it to null serves no useful purpose.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Fanatic Member popskie's Avatar
    Join Date
    Jul 2005
    Location
    In my chair
    Posts
    666

    Re: clearing datareader in memory?

    yap i can create that way. and thanks for ur advice.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width