Variable does not exist - but does?

  • Thread starter Thread starter tshad
  • Start date Start date
T

tshad

Using VS 2005:

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

public string UpdateTables(TableFieldList tableFields,
UnmappedNamesCollection unmappedNames, DataView dv)
{
bool newSection = false;
bool parameterExists = false; <---- Here is defined
foreignKeys = new ForeignKeyCollection();

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

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

The error is:

The name 'parameterExists' 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
 
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 said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top