Click here to Skip to main content
15,888,733 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Project name is OTS.
i have assign this variable in product form
public static string productname;


But i want to using that variable in AddProductForm

But it is not access in
AddProductForm


What I have tried:

i have try
Product.productname

in AddProductForm. But it is giving error.
If i type this
OTS.Product.productname
then it is working.
Why it is not working without project name.
Posted
Updated 5-Apr-18 2:46am
v2

Using static variables to share data like this is usually a result of bad design. Each form is an instance of an object so you should hold data in public properties of the forms instead.

As for your actual question, this is to do with namespaces and is one of the most basic aspects of .net. If you don't understand namespaces then you're going to struggle doing any effective coding in .net. I suggest you get a book on c# and go through it to get an understanding of the basics before you tackle your project.
 
Share this answer
 
Comments
Member 11776570 5-Apr-18 6:39am    
But the problem is that, there in no error in other windows form. In other windows form it is working without the OTS namespace, but not working in product form.
F-ES Sitecore 5-Apr-18 6:47am    
Google for articles on namespaces and how they work. You can't expect us to explain every aspect of development to you in a serious of forum posts. This stuff is extensively documented.
Typically, if a form needs some piece of data, you pass that data to the form in either it's constructor, some properties the new form exposes, or some method on that form. It should NEVER have to beg another form or class for the data it needs.

You're current model does that. It's not up to the new form to go looking around the app for the data it needs. That data should be handed to it by whatever code is instantiating the new form.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900