Avatar of g_johnson
g_johnsonFlag for United States of America asked on

scope issue C#, VS2008

In the C# code attached, when setting a breakpoint inside the foreach after the ItemNo = blah blah blah statement, in the immediate window I get

?ItemNo
The name 'ItemNo' does not exist in the current context

However, this returns the value I am looking for

?(string)LineItem.Element(sync + "Item").Element(sync + "ItemID").Element(sync + "ID").Value
"HEWC8011A"


What am I doing wrong?  VS2008

var LineItems = from el in ord.Elements(sync + "DataArea")
                 .Elements(sync + "SalesOrder")
                 .Elements(sync + "SalesOrderLine")
                                select el;

                string ItemNo = "";
                string loc = "";
                double qty_ordered = 0;
                double price = 0;

                foreach (var LineItem in LineItems)
                {
                    ItemNo = (string)LineItem.Element(sync + "Item").Element(sync + "ItemID").Element(sync + "ID").Value;

                    OrderHeader.OrdLines.Add(new OrderLine()
                    {
                        item_no = ItemNo,
                        loc = loc,
                        qty_ordered = qty_ordered,
                        price = price,
                        promDate = DateTime.Now.Date,
                        reqDate = DateTime.Now.Date,
                        reqShipDate = DateTime.Now.Date,
                    });

                    ItemNo = "";
                    loc = "";
                    qty_ordered = 0;
                    price = 0;
                }

Open in new window

C#

Avatar of undefined
Last Comment
g_johnson

8/22/2022 - Mon
kaufmed

How and where is ItemNo declared?
kaufmed

Nevermind, I missed it.
ASKER CERTIFIED SOLUTION
Todd Gerbert

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
g_johnson

I came in today, changed it to ItemNumber and it worked.  But the variable ItemNo does not appear anywhere in my class except here.  So, out of curiosity, I changed it back and it worked still (as ItemNo).  Very strange!  Thanks for the help
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23