Help writing conditional blocks

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • estafford

    #1

    Help writing conditional blocks

    I am having trouble writing a conditional block using ASP.NET and C#.

    I am trying to do something like this:
    1. if page is PostBack
    - transfer to another page

    2. if not postback
    - connect to database and get information using a querystring id and create
    a DataReader (as DR).
    - generate a Form to display using values from the database query.

    The problem is that I get an error:
    The name 'DR' does not exist in the class or namespace 'ASP.contact_as px'

    Because the page is not postback, the DataReader object is not created.
    Is there any way around this?

    I assumed that the code in condition 2 would be skipped because the
    condition was false but it seems to trying to run through it anyway.
    This process works in classic ASP but I cannot get it to work in ASP.NET.

    I'd like to try to keep this confined to one page.
    Suggestions??


  • Carl Prothman [MVP]

    #2
    Re: Help writing conditional blocks

    "estafford" <estafford your pants @newmancom.com> wrote[color=blue]
    > I am having trouble writing a conditional block using ASP.NET and C#.
    > I am trying to do something like this:
    > 1. if page is PostBack
    > - transfer to another page
    > 2. if not postback
    > - connect to database and get information using a querystring id and create
    > a DataReader (as DR).
    > - generate a Form to display using values from the database query.
    >
    > The problem is that I get an error:
    > The name 'DR' does not exist in the class or namespace 'ASP.contact_as px'
    >[/color]

    Did you include the "Imports System.Data.Sql Client" statement (for VB.NET) or
    "using System.Data;" statement (for C#) at the top of your code-behind file?

    Also, keep in mind, when you DIM an var in an IF statement, then that var only
    has scope within the IF statement block. Same is true for TRY CATCH blocks...

    --

    Thanks,
    Carl Prothman
    Microsoft ASP.NET MVP


    [color=blue]
    > Because the page is not postback, the DataReader object is not created.
    > Is there any way around this?
    >
    > I assumed that the code in condition 2 would be skipped because the
    > condition was false but it seems to trying to run through it anyway.
    > This process works in classic ASP but I cannot get it to work in ASP.NET.
    >
    > I'd like to try to keep this confined to one page.
    > Suggestions??
    >
    >[/color]


    Comment

    • estafford

      #3
      Re: Help writing conditional blocks

      Bingo!!
      Thanks Carl. Turns out I did not declair the DR variable outside the
      function.
      I assumed it was something more difficult and overlooked the obvious.

      Such is the learning process...
      Thanks Again.

      "Carl Prothman [MVP]" <carlpr@spamcop .net> wrote in message
      news:OAv6s1nZDH A.2284@TK2MSFTN GP12.phx.gbl...[color=blue]
      > "estafford" <estafford your pants @newmancom.com> wrote[color=green]
      > > I am having trouble writing a conditional block using ASP.NET and C#.
      > > I am trying to do something like this:
      > > 1. if page is PostBack
      > > - transfer to another page
      > > 2. if not postback
      > > - connect to database and get information using a querystring id and[/color][/color]
      create[color=blue][color=green]
      > > a DataReader (as DR).
      > > - generate a Form to display using values from the database query.
      > >
      > > The problem is that I get an error:
      > > The name 'DR' does not exist in the class or namespace[/color][/color]
      'ASP.contact_as px'[color=blue][color=green]
      > >[/color]
      >
      > Did you include the "Imports System.Data.Sql Client" statement (for VB.NET)[/color]
      or[color=blue]
      > "using System.Data;" statement (for C#) at the top of your code-behind[/color]
      file?[color=blue]
      >
      > Also, keep in mind, when you DIM an var in an IF statement, then that var[/color]
      only[color=blue]
      > has scope within the IF statement block. Same is true for TRY CATCH[/color]
      blocks...[color=blue]
      >
      > --
      >
      > Thanks,
      > Carl Prothman
      > Microsoft ASP.NET MVP
      > http://www.able-consulting.com
      >
      >[color=green]
      > > Because the page is not postback, the DataReader object is not created.
      > > Is there any way around this?
      > >
      > > I assumed that the code in condition 2 would be skipped because the
      > > condition was false but it seems to trying to run through it anyway.
      > > This process works in classic ASP but I cannot get it to work in[/color][/color]
      ASP.NET.[color=blue][color=green]
      > >
      > > I'd like to try to keep this confined to one page.
      > > Suggestions??
      > >
      > >[/color]
      >
      >[/color]


      Comment

      Working...