g_johnson
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
?ItemNo
The name 'ItemNo' does not exist in the current context
However, this returns the value I am looking for
?(string)LineItem.Element(
"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;
}
How and where is ItemNo declared?
Nevermind, I missed it.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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