Re: A question about closing the SqlDataReader

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



I am a newbie and using VB.Net. I had understood that Using was
equivalent to Imports. I know read in the online help that it also can
be used to define scope, as you are indicating here. Is there an
equivalent in VB.Net to this construct?

TIA
John

On Wed, 30 Mar 2005 21:37:19 +0200, "Miha Markic [MVP C#]" <miha at
rthand com> wrote:

>Yes, it is necessary to close it.
>More slick way would be (note that you don't need explicit Close call - it
>is handled through implicit Dispose):
>
>using (SqlDataReader reader = cmd.ExecuteReader())
>{
>if (reader.Read())
>> {
>> // do something here
>> }
>> else
>> {
>> Response.Redirect("to_some_other_page.aspx");
>> }
>}

.



Relevant Pages

  • Re: Help with Java servlet : getServletContext().
    ... > I am newbie to Java, am trying to get a program working, and I have ... > imported the java packages below along with many other imports: ...
    (comp.lang.java.help)
  • Re: conditional plot
    ... Marin Ion wrote: ... I am a "more than newbie in MatLab". ... I've checked the online help, but I'm either stupid or blind because ...
    (comp.soft-sys.matlab)
  • Re: find the last row number
    ... Frank Kabel ... Newbie wrote: ... > I have some code that imports a text file into a template. ... > F-I there are some formulaes that I need to copy down to the last row ...
    (microsoft.public.excel.programming)
  • How do I set up the hyperlink properties from a non-frame page to framed page to appear in the main
    ... I'm a newbie using FrontPage 2003 and have looked for online help to answer this question but have not had any luck yet. ...
    (microsoft.public.frontpage.client)
  • Pause between Macros
    ... I'm running a macro that imports ... I need to know how to keep the next macro from running until this ... If you have a VB answer, please write you suggestion ... where a newbie like me can understand. ...
    (microsoft.public.access.macros)