Link to home
Start Free TrialLog in
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

Avatar of kaufmed
kaufmed
Flag of United States of America image

How and where is ItemNo declared?
Nevermind, I missed it.
ASKER CERTIFIED SOLUTION
Avatar of Todd Gerbert
Todd Gerbert
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of g_johnson

ASKER

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