By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,109 Members | 932 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,109 IT Pros & Developers. It's quick & easy.

classes

P: 26
dear all

I wrote a class called "sqldatabase" and this class has variable caleld Buliding

and from other class I tried to insert the string inside buliding variable
and I got these message

"Object reference not set to an instance of an object"

here the code

public partial class Import : Form
{
sqldatabase a = null;
public Import()
{

InitializeComponent();
}




private void Inst1_Click(object sender, EventArgs e)
{
a.Buliding = Buliding.Text.ToString();
}

so how make this reference between two lcass such that I can access one class through the other?
thanks
Feb 16 '09 #1
Share this Question
Share on Google+
2 Replies


100+
P: 179
Without more detail about your classes it's hard to tell what you're trying to do exactly...

but change

sqldatabase a = null;

to sqldatabase a = new sqldatabase();

Also, capitalise your classes. SqlDataBase...
Feb 17 '09 #2

Expert 100+
P: 427
Hi

From the code supplied, you will get the error message unless variable 'a' is declared as a global variable.

In addition to Ian's post, the code I quoted below:

a.Buliding = Buliding.Text.ToString();
This looks really strange, to me this looks like you have an object 'a' with a property 'Building' which you want to make equal to a property from another object called 'Building'. Just be sure that property "Building" of object 'a' is a string or you will get a type casting error.

I suggest you post your class (Just the interface to the class should be enough) and then all the code in the file which causes the error, without that info the best we can do is guess what might be wrong.
Feb 17 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.