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

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
 
S

Stefan Hoffmann

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 <--
 
I

Ignacio Machin ( .NET/ C# MVP )

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.
 
F

Family Tree Mike

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top