Variable does not exist - but does?

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

    Variable does not exist - but does?

    Using VS 2005:

    Here is a piece of code that is saying that a variable doesn't exist which
    obviously does:

    public string UpdateTables(Ta bleFieldList tableFields,
    UnmappedNamesCo llection unmappedNames, DataView dv)
    {
    bool newSection = false;
    bool parameterExists = false; <---- Here is defined
    foreignKeys = new ForeignKeyColle ction();

    using (conn = new SqlConnection(C onnectString))
    {
    try
    {
    conn.Open();

    foreach (TableField tf in tableFields)
    {
    parameterExists = false; <--------
    Error
    ....

    The error is:

    The name 'parameterExist s' does not exist in the current context

    How can that be?

    It is global for the function so how can that error be there?

    Is the "using" causing a problem?

    Or am I just having a brain fade here?

    Thanks,

    Tom


  • Peter Duniho

    #2
    Re: Variable does not exist - but does?

    On Sun, 01 Jun 2008 16:33:37 -0700, tshad <tshad@dslextre me.comwrote:
    [...]
    The error is:
    >
    The name 'parameterExist s' does not exist in the current context
    >
    How can that be?
    Surely the fraction of code that you posted is not exactly the same as the
    code actually suffering the error.

    If you can post a concise-but-complete code sample that demonstrates the
    error, it's probably possible to point out the problem. Otherwise, I
    don't think so.

    If I had to guess, I'd guess typo somewhere, either in the declaration or
    the use. Much less likely (but still possible) is the possibility that
    you're coding in Unicode and managed to get a typographically aliased
    character into the variable name. Suffice to say, if the name as used was
    actually exactly the same as the name as declared, and the structure of
    the code was exactly as you've posted here, you wouldn't be getting the
    compiler error.

    Pete

    Comment

    • =?Utf-8?B?VGFyaXEgQWJkdWwgS2FyaW0=?=

      #3
      RE: Variable does not exist - but does?

      I did not find any problem in the given piece of code. However since you are
      having a compile-time error, I can reduce the area of investigation by
      assuring you that "using" construct does not change the scope or life of a
      variable. It is similar to other language structures as foreach or while
      loop. Thus if you could paste the complete code, probably we could help you
      better.
      --
      Tariq Abdul Karim

      Blogger ist ein Veröffentlichungs-Tool von Google, mit dem du ganz einfach deine Gedanken der Welt mitteilen kannst. Mit Blogger kannst du problemlos Texte, Fotos und Videos in deinem persönlichen Blog oder deinem Team-Blog veröffentlichen.



      "tshad" wrote:
      Using VS 2005:
      >
      Here is a piece of code that is saying that a variable doesn't exist which
      obviously does:
      >
      public string UpdateTables(Ta bleFieldList tableFields,
      UnmappedNamesCo llection unmappedNames, DataView dv)
      {
      bool newSection = false;
      bool parameterExists = false; <---- Here is defined
      foreignKeys = new ForeignKeyColle ction();
      >
      using (conn = new SqlConnection(C onnectString))
      {
      try
      {
      conn.Open();
      >
      foreach (TableField tf in tableFields)
      {
      parameterExists = false; <--------
      Error
      ....
      >
      The error is:
      >
      The name 'parameterExist s' does not exist in the current context
      >
      How can that be?
      >
      It is global for the function so how can that error be there?
      >
      Is the "using" causing a problem?
      >
      Or am I just having a brain fade here?
      >
      Thanks,
      >
      Tom
      >
      >
      >

      Comment

      • tshad

        #4
        Re: Variable does not exist - but does?

        "Tariq Abdul Karim" <TariqAbdulKari m@discussions.m icrosoft.comwro te in
        message news:2A006A4D-B07D-4A25-8628-83DF8B9E6FAC@mi crosoft.com...
        >I did not find any problem in the given piece of code. However since you
        >are
        having a compile-time error, I can reduce the area of investigation by
        assuring you that "using" construct does not change the scope or life of a
        variable. It is similar to other language structures as foreach or while
        loop. Thus if you could paste the complete code, probably we could help
        you
        better.
        Well, it is working now and I don't know why.

        I did comment it out to get it to build, which it did and when I came back
        to copy it to paste in the code here, I uncommented it and it worked fine.

        So I don't know what was causing it, but it works now.

        Thanks,

        Tom
        --
        Tariq Abdul Karim
        >
        Blogger ist ein Veröffentlichungs-Tool von Google, mit dem du ganz einfach deine Gedanken der Welt mitteilen kannst. Mit Blogger kannst du problemlos Texte, Fotos und Videos in deinem persönlichen Blog oder deinem Team-Blog veröffentlichen.

        >
        >
        "tshad" wrote:
        >
        >Using VS 2005:
        >>
        >Here is a piece of code that is saying that a variable doesn't exist
        >which
        >obviously does:
        >>
        > public string UpdateTables(Ta bleFieldList tableFields,
        >UnmappedNamesC ollection unmappedNames, DataView dv)
        >{
        > bool newSection = false;
        > bool parameterExists = false; <---- Here is
        >defined
        > foreignKeys = new ForeignKeyColle ction();
        >>
        > using (conn = new SqlConnection(C onnectString))
        > {
        > try
        > {
        > conn.Open();
        >>
        > foreach (TableField tf in tableFields)
        > {
        > parameterExists = false; <--------
        >Error
        >....
        >>
        >The error is:
        >>
        > The name 'parameterExist s' does not exist in the current context
        >>
        >How can that be?
        >>
        >It is global for the function so how can that error be there?
        >>
        >Is the "using" causing a problem?
        >>
        >Or am I just having a brain fade here?
        >>
        >Thanks,
        >>
        >Tom
        >>
        >>
        >>

        Comment

        Working...