An object reference is required for the non-static field,method or property

  • Thread starter Thread starter Uday
  • Start date Start date
U

Uday

Hi Everybody,

proj1-frmCatSql.cs contains a method like

public datatable GetallMembers() { stms--------- }

proj2-frmItem.cs conatins

private void Filldata(combobox cmb, datatable dtlname) { stmts------- }

private viod frmitem_load( ) {
Filldata( cmbcate, catesql.Getallmembers())

Note: catesql is class of frmCatsql.cs
Here I get an error at catesql.Getallmembers() as An object reference is
required for non-static, method or property.

I can't make the method as static. B'coz itz referencing to another
methods where they wer defined as Abstract and Override methods.

Please suggest me how to resolve these error. Hope everbody understood.
Please send me as soon as possible


Uday Raju
 
hi,
Note: catesql is class of frmCatsql.cs
Here I get an error at catesql.Getallmembers() as An object reference is
required for non-static, method or property.
This normally indicates that catesql == null.

mfG
--> stefan <--
 
Hi Everybody,

proj1-frmCatSql.cs contains a method like

public datatable GetallMembers() { stms--------- }

proj2-frmItem.cs conatins

private void Filldata(combobox cmb, datatable dtlname) { stmts------- }

private viod frmitem_load( ) {
Filldata( cmbcate, catesql.Getallmembers())

Note: catesql is class of frmCatsql.cs
Here I get an error at catesql.Getallmembers() as An object reference is
required for non-static, method or property.

I can't make the method as static. B'coz itz referencing to another
methods where they wer defined as Abstract and Override methods.

Please suggest me how to resolve these error. Hope everbody understood.
Please send me as soon as possible

Uday Raju

*** Sent via Developersdexhttp://www.developersdex.com***

Is this occurring at runtime or at compile?

You have two options , you either make your method static (this will
imply a change in your classes as you explained) or you cannot call it
from a static method.
 
Uday said:
Hi Everybody,

proj1-frmCatSql.cs contains a method like

public datatable GetallMembers() { stms--------- }

proj2-frmItem.cs conatins

private void Filldata(combobox cmb, datatable dtlname) { stmts------- }

private viod frmitem_load( ) {
Filldata( cmbcate, catesql.Getallmembers())

Note: catesql is class of frmCatsql.cs
Here I get an error at catesql.Getallmembers() as An object reference is
required for non-static, method or property.

I can't make the method as static. B'coz itz referencing to another
methods where they wer defined as Abstract and Override methods.

Please suggest me how to resolve these error. Hope everbody understood.
Please send me as soon as possible


Uday Raju

If proj2-frmItem is created from proj1-frmCatSql, then I would add an
argument to the constructor to pass the instance of proj1-frmCatSql. You
could then use that instance to call Getallmembers().

Mike
 
Back
Top