Data binding: object reference required

C

cppquester

I have a data set
MMSDataAccess
with:
public partial class MMSDataSet : System.Data.DataSet {

...

private TB_ACTHEATDATADataTable tableTB_ACTHEATDATA;

...

public TB_ACTHEATDATADataTable TB_ACTHEATDATA {
get {
return this.tableTB_ACTHEATDATA;
}
}

...
}


and a component for editin it
MMSDBEditControl:

with

partial class MMSDBEditControl
{

private void InitializeComponent()
{
...
this.mMSDataSet = new MMSDataAccess.MMSDataSet();
...
}

}


Above is all designer gernerated code.

But when I do:

using MMSDataAccess;
using MMSDataAccess.MMSDataSetTableAdapters;

namespace MMSDBEdit
{

public partial class MMSDBEditControl : UserControl
{
public MMSDBEditControl()
{
InitializeComponent();


TB_ACTHEATDATATableAdapter.Fill( this.mMSDataSet.TB_ACTHEATDATA); //
Error here
}

....
}
}


I get
Error 1 An object reference is required for the nonstatic field,
method, or property
'MMSDataAccess.MMSDataSetTableAdapters.TB_ACTHEATDATATableAdapter.Fill(MMSDataAccess.MMSDataSet.TB_ACTHEATDATADataTable)'
C:\Project\MMS\MMSDBEditControl.cs 20


Does somebody understand why that is?
I would think the Fill method got exactly what it is demanding.

Thanks,
Marc
 
C

cppquester

I have a data set
MMSDataAccess
with:
public partial class MMSDataSet : System.Data.DataSet {

...

private TB_ACTHEATDATADataTable tableTB_ACTHEATDATA;

...

public TB_ACTHEATDATADataTable TB_ACTHEATDATA {
get {
return this.tableTB_ACTHEATDATA;
}
}

...
}

and a component for editin it
MMSDBEditControl:

with

partial class MMSDBEditControl
{

private void InitializeComponent()
{
...
this.mMSDataSet = new MMSDataAccess.MMSDataSet();
...
}

}

Above is all designer gernerated code.

But when I do:

using MMSDataAccess;
using MMSDataAccess.MMSDataSetTableAdapters;

namespace MMSDBEdit
{

public partial class MMSDBEditControl : UserControl
{
public MMSDBEditControl()
{
InitializeComponent();

TB_ACTHEATDATATableAdapter.Fill( this.mMSDataSet.TB_ACTHEATDATA); //
Error here
}

...
}

}

I get
Error 1 An object reference is required for the nonstatic field,
method, or property
'MMSDataAccess.MMSDataSetTableAdapters.TB_ACTHEATDATATableAdapter.Fill(MMSDataAccess.MMSDataSet.TB_ACTHEATDATADataTable)'
C:\Project\MMS\MMSDBEditControl.cs 20

Does somebody understand why that is?
I would think the Fill method got exactly what it is demanding.

Thanks,
Marc

ok, found the solution myself:
The object reference required related to the object on which Fill was
called
(this).

However: Why there is no tebale adapter hold by the MMSDataSet
as it holds the table itself as well?
 
J

Jon Skeet [C# MVP]

On Nov 26, 10:11 am, (e-mail address removed) wrote:

The object reference required related to the object on which Fill was
called (this).

However: Why there is no tebale adapter hold by the MMSDataSet
as it holds the table itself as well?

The adapter populates the data set, but there's no reason for the data
set to keep hold of the table adapter. In particular, a single table
adapter could populate many data sets. It's just a conduit between the
in memory data and the database, really.

Jon
 
C

cppquester

On Nov 26, 10:11 am, (e-mail address removed) wrote:




The adapter populates the data set, but there's no reason for the data
set to keep hold of the table adapter. In particular, a single table
adapter could populate many data sets. It's just a conduit between the
in memory data and the database, really.

Jon

Thanks for the answer.
So everytime a TA is needed I should create it new?
That leaves no big overhead? Or is there even a benefit
(e.g. releasing memory used for the fill)?

Marc
 
J

Jon Skeet [C# MVP]

Thanks for the answer.
So everytime a TA is needed I should create it new?
That leaves no big overhead? Or is there even a benefit
(e.g. releasing memory used for the fill)?

I'm not an expert on the adapter side of things, but I believe it's
fine to create a new one each time.

Jon
 
Top