classes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • little83
    New Member
    • Feb 2009
    • 26

    classes

    dear all

    I wrote a class called "sqldatabas e" 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()
    {

    InitializeCompo nent();
    }




    private void Inst1_Click(obj ect sender, EventArgs e)
    {
    a.Buliding = Buliding.Text.T oString();
    }

    so how make this reference between two lcass such that I can access one class through the other?
    thanks
  • IanWright
    New Member
    • Jan 2008
    • 179

    #2
    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...

    Comment

    • cloud255
      Recognized Expert Contributor
      • Jun 2008
      • 427

      #3
      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.T oString();
      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.

      Comment

      Working...