Hi friend,
here i have written a sample code for the client to access a class members in the BLL through another class:
namespace WindowsFormsApplication18
{
public partial class Form1 : Form
{
A a;
public Form1()
{
InitializeComponent();
}
public void Save()
{
a = new A();
a._b.address = "hello"; // here i can access the members of "b" using the reference
a._b.city = "sdfsf"; // same
}
}
}
namespace Test1
{
public class A
{
public string name { get; set; }
public int id { get; set; }
public B _b;
public A()
{
_b = new B();
}
}
public class B
{
public string address { get; set; }
public string city { get; set; }
}
}
and now i have written an actual application that follows the same pattern to acess te member of class through anther class:
public class InventoryItem
{
internal MasterItemInventory myMasterItemInventory;
public ItemStockLevel _MyItemStockLevel;
public InventoryItem()
{
try
{
myMasterItemInventory = new MasterItemInventory();
_MyItemStockLevel = new ItemStockLevel();
}
catch
{
throw;
}
}
public byte Save()
{
try
{
return myMasterItemInventory.Save(this);
}
catch
{
throw;
}
}
}
public class ItemStockLevel
{
public int ItemID { get; set; }
public int StockTakeDate { get; set; }
public int QIS { get; set; }
public ItemStockLevel()
{
//no code
}
public byte Save()
{
//no code
}
}
//client form
using ICSBLL;
namespace InventoryControlSystem
{
public partial class frmInventoryItemAdmin : Form
{
InventoryItem myIventoryItem;
//ItemStockLevel myItemStockLevel;
public frmInventoryItemAdmin()
{
InitializeComponent();
}
private void btnSave_Click(object sender, EventArgs e)
{
myIventoryItem._MyItemStockLevel.QIS = int.Parse(nmudQIS.Value.ToString()); // HERE I CANNOT ACCESS THE MEMBERS
myIventoryItem._MyItemStockLevel.StockTakeDate = int.Parse(cmbStockTakeDate.Text);//HERE I CANNOT ACCESS THE MEMBERS
myIventoryItem._MyItemStockLevel.QIS = 1; //HERE I CANNOT ACCESS THE MEMBERS
byte scode = myIventoryItem.Save();
}
the classes InventoryItem and ItemStockLevel are in the namespace ICSBLL...
when i compile i receive the error:
Error 2 'ICSBLL.InventoryItem' does not contain a definition for '_MyItemStockLevel' and no extension method '_MyItemStockLevel' accepting a first argument of type 'ICSBLL.InventoryItem' could be found (are you missing a using directive or an assembly reference?) F:\C#\Lab\InventoryControlSystem\InventoryControlSystem\frmInventoryItemAdmin.cs 62 29 InventoryControlSystem
Do you know why i can access in the first code and not in the second event if i follow the same pattern?
thanks

4 answers
Well, I can't see anything wrong with the application code and, with a few minor changes for code you haven't posted, even managed to get it to compile.
The compiler is certainly finding the class ICSBLL.InventoryItem or you'd get a different error but isn't finding a member called _MyItemStockLevel even though there is a public field of that name.
The only thing I can think of is that this member is spelled differently in your actual code.
If that's not the case, what members show up for this class in intellisense?
answered one year ago by:
17279
the _MyItemStockLevel popsup on the intelisense also when put dot after _MyItemStockLevel it popups up all the mmebrs of he ItemStockLevel class as well but when assigne a value to it, it give the above error im really annoyed with this bug becuase i cannot continue my app wih it.
If you would like ot look at the code here is link that iave attached:
http://www.mediafire.com/?hm0ywwzjzym
thanks
answered one year ago by:
0
17279
I couldn't find anything wrong with it. In fact, after fixing a couple of small errors (nothing to do with the present problem or non-matching namespaces), it built and ran fine! I'd try deleting the offending lines and then typing them in again and/or closing VS and reopening it. Sometimes this clears obscure problems such as this.
namespaces for partial classes must match. I haven't looked too closely, but it looks like they don't match at a glance.
answered one year ago by:
2309
hi friend
1. each time when sit i reopn the VS, but it didnt fx the problem
2. i cant see any issus withe namespace, at my starting thead i have showed it
3. you are correct, when i remove the likes that gives error it builds. But i need those lines so that i could assign values to ItemStockLevel object
4.I'v tried re typing, it even shows the reference variables _MyItemStockLevel under insellisense it even show the members of ItemStocklevel under _MyItemStockLevel but when i assign a value with the correct type it gives the issue
How annoyng this could be, do you think the VS stuffing up my code, then how come it worked for the small example snippet that i have given in the starting post?
thanks
answered one year ago by:
0
17279
This has to be some problem with VS itself as there's clearly no problem with the code itself. Possibly some non-printing characters have got into the file where the field is defined. I'd try looking at the InventoryItem class and deleting the line: public ItemStockLevel _MyItemStockLevel; and typing it back in again. If it's still no better, try using a different name for that field and then do a search/replace to change all references to it in the rest of the program.