PC Review


Reply
Thread Tools Rate Thread

Data binding: object reference required

 
 
cppquester@googlemail.com
Guest
Posts: n/a
 
      26th Nov 2007
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


 
Reply With Quote
 
 
 
 
cppquester@googlemail.com
Guest
Posts: n/a
 
      26th Nov 2007
On Nov 26, 10:41 am, cppques...@googlemail.com wrote:
> 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?
 
Reply With Quote
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      26th Nov 2007
On Nov 26, 10:11 am, cppques...@googlemail.com wrote:

<snip>

> 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
 
Reply With Quote
 
cppquester@googlemail.com
Guest
Posts: n/a
 
      26th Nov 2007
On Nov 26, 11:19 am, "Jon Skeet [C# MVP]" <sk...@pobox.com> wrote:
> On Nov 26, 10:11 am, cppques...@googlemail.com wrote:
>
> <snip>
>
> > 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


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


 
Reply With Quote
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      26th Nov 2007
On Nov 26, 4:22 pm, cppques...@googlemail.com wrote:
> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
An object reference is required for the nonstatic field, method or =?Utf-8?B?QUEyZTcyRQ==?= Microsoft C# .NET 1 25th May 2007 10:07 AM
An object reference is required simonZ Microsoft C# .NET 2 28th Aug 2006 02:13 PM
Help: object reference is required for the nonstatic field TdJ Microsoft C# .NET 1 14th Nov 2003 05:53 PM
Object reference required (question) Bucko Microsoft ASP .NET 0 24th Oct 2003 12:15 AM
Object reference is required DC Microsoft C# .NET 2 27th Aug 2003 09:23 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:15 AM.