nullreferenceexception in system.data.dll

  • Thread starter Thread starter Christian Westerlund
  • Start date Start date
C

Christian Westerlund

Hi!

I have a problem in my application where I have a datagrid.
the datasource is a datatable which I update every 6:th second.

foreach( Sobject s in sArrayList){

foreach( SSObject so in Sobject.array){


dT.Rows[x] =
(Myobject)so).T.Current;


}

}

I get an
"An unhandled exception of type 'System.NullReferenceException' occurred
in System.Data.dll"

when I scroll the datagrid down and upp for a minute or something like that.

The code jumps to:
static void Main()
{
Application.Run(new FrmMyApp()); }

If I take away the dT.Rows[x] row I don't get an exception.
If I set dT.Rows[x] = "1"
I don't get any exceptions.
If I replace the dT.Rows row with this:
float t = (Myobject)so).T.Current;
I don't get an exception.

I only get an exception when I combine them.

I have added this to my code but it doesn't seem to help:
dT.BeginLoadData();
lock( sArrayList.SyncRoot){

my code

}
dT.EndLoadData();

I would appreciate every help I could get on this.
/Christian
 
I do get I an exception when I write:
If I set dT.Rows[x] = "1"
And I don't even have to scroll the datagrid to get an exception.
This is the only place where I access this datatable, I have a
connection between the grid and the table:
dG.DataSource = dT;

/Christian
 
I read that a write operation on a datatable must be synchronized so I
added the following lines:
lock( dTDetailTemperatures.Rows.SyncRoot ){
// code that writes to the datatable
dT.Rows[x] = "1";
}


Christian said:
I do get I an exception when I write:
If I set dT.Rows[x] = "1"
And I don't even have to scroll the datagrid to get an exception.
This is the only place where I access this datatable, I have a
connection between the grid and the table:
dG.DataSource = dT;

/Christian




Christian said:
Hi!

I have a problem in my application where I have a datagrid.
the datasource is a datatable which I update every 6:th second.

foreach( Sobject s in sArrayList){

foreach( SSObject so in Sobject.array){


dT.Rows[x] =
(Myobject)so).T.Current;


}

}

I get an
"An unhandled exception of type 'System.NullReferenceException'
occurred in System.Data.dll"

when I scroll the datagrid down and upp for a minute or something like
that.

The code jumps to:
static void Main()
{
Application.Run(new FrmMyApp()); }

If I take away the dT.Rows[x] row I don't get an exception.
If I set dT.Rows[x] = "1"
I don't get any exceptions.
If I replace the dT.Rows row with this:
float t = (Myobject)so).T.Current;
I don't get an exception.

I only get an exception when I combine them.

I have added this to my code but it doesn't seem to help:
dT.BeginLoadData();
lock( sArrayList.SyncRoot){

my code

}
dT.EndLoadData();

I would appreciate every help I could get on this.
/Christian
 
It seems that the datarowcollection doesn't get synchronized because
when I add this code:

if( dT.Rows.IsSynchronized) dT.Rows[x] = "1"; else
MessageBox.Show("not sync");
I get a messagebox instead of a write to the datatable

/Christian


Christian said:
I read that a write operation on a datatable must be synchronized so I
added the following lines:
lock( dTDetailTemperatures.Rows.SyncRoot ){
// code that writes to the datatable
dT.Rows[x] = "1";
}


Christian said:
I do get I an exception when I write:
If I set dT.Rows[x] = "1"
And I don't even have to scroll the datagrid to get an exception.
This is the only place where I access this datatable, I have a
connection between the grid and the table:
dG.DataSource = dT;

/Christian




Christian said:
Hi!

I have a problem in my application where I have a datagrid.
the datasource is a datatable which I update every 6:th second.

foreach( Sobject s in sArrayList){

foreach( SSObject so in Sobject.array){


dT.Rows[x] =
(Myobject)so).T.Current;


}

}

I get an
"An unhandled exception of type 'System.NullReferenceException'
occurred in System.Data.dll"

when I scroll the datagrid down and upp for a minute or something
like that.

The code jumps to:
static void Main()
{
Application.Run(new FrmMyApp()); }

If I take away the dT.Rows[x] row I don't get an exception.
If I set dT.Rows[x] = "1"
I don't get any exceptions.
If I replace the dT.Rows row with this:
float t = (Myobject)so).T.Current;
I don't get an exception.

I only get an exception when I combine them.

I have added this to my code but it doesn't seem to help:
dT.BeginLoadData();
lock( sArrayList.SyncRoot){

my code

}
dT.EndLoadData();

I would appreciate every help I could get on this.
/Christian
 
Christian,

Please use Control.Invoke to update DataSet on DataGrid's thread.

This article contains a sample on how to do it.

http://msdn.microsoft.com/mobility/understanding/articles/default.aspx?pull=
/library/en-us/dnnetcomp/html/backgroundprocess.asp

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
Date: Mon, 08 Mar 2004 12:26:53 +0100
From: Christian Westerlund <[email protected]>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.6b) Gecko/20031205 Thunderbird/0.4
X-Accept-Language: en-us, en
MIME-Version: 1.0
Subject: Re: nullreferenceexception in system.data.dll
References: <[email protected]>
In-Reply-To: <[email protected]>
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.compactframework
NNTP-Posting-Host: h198n2fls28o1063.bredband.comhem.se 217.209.125.198
Lines: 1
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.compactframework:47880
X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework

It seems that the datarowcollection doesn't get synchronized because
when I add this code:

if( dT.Rows.IsSynchronized) dT.Rows[x] = "1"; else
MessageBox.Show("not sync");
I get a messagebox instead of a write to the datatable

/Christian


Christian said:
I read that a write operation on a datatable must be synchronized so I
added the following lines:
lock( dTDetailTemperatures.Rows.SyncRoot ){
// code that writes to the datatable
dT.Rows[x] = "1";
}


Christian said:
I do get I an exception when I write:
If I set dT.Rows[x] = "1"
And I don't even have to scroll the datagrid to get an exception.
This is the only place where I access this datatable, I have a
connection between the grid and the table:
dG.DataSource = dT;

/Christian




Christian Westerlund wrote:

Hi!

I have a problem in my application where I have a datagrid.
the datasource is a datatable which I update every 6:th second.

foreach( Sobject s in sArrayList){

foreach( SSObject so in Sobject.array){


dT.Rows[x] =
(Myobject)so).T.Current;


}

}

I get an
"An unhandled exception of type 'System.NullReferenceException'
occurred in System.Data.dll"

when I scroll the datagrid down and upp for a minute or something
like that.

The code jumps to:
static void Main()
{
Application.Run(new FrmMyApp()); }

If I take away the dT.Rows[x] row I don't get an exception.
If I set dT.Rows[x] = "1"
I don't get any exceptions.
If I replace the dT.Rows row with this:
float t = (Myobject)so).T.Current;
I don't get an exception.

I only get an exception when I combine them.

I have added this to my code but it doesn't seem to help:
dT.BeginLoadData();
lock( sArrayList.SyncRoot){

my code

}
dT.EndLoadData();

I would appreciate every help I could get on this.
/Christian

 
Thanks, it seems to work!
I did this:

dG.Invoke( new EventHandler(UpdateDisplay) );

Whenever I was about to write in the datatable.

/Christian
Christian,

Please use Control.Invoke to update DataSet on DataGrid's thread.

This article contains a sample on how to do it.

http://msdn.microsoft.com/mobility/understanding/articles/default.aspx?pull=
/library/en-us/dnnetcomp/html/backgroundprocess.asp

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
Date: Mon, 08 Mar 2004 12:26:53 +0100
From: Christian Westerlund <[email protected]>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.6b)

Gecko/20031205 Thunderbird/0.4
X-Accept-Language: en-us, en
MIME-Version: 1.0
Subject: Re: nullreferenceexception in system.data.dll
References: <[email protected]>

<#[email protected]>
In-Reply-To: <[email protected]>
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.compactframework
NNTP-Posting-Host: h198n2fls28o1063.bredband.comhem.se 217.209.125.198
Lines: 1
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.compactframework:47880

X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework

It seems that the datarowcollection doesn't get synchronized because
when I add this code:

if( dT.Rows.IsSynchronized) dT.Rows[x] = "1"; else
MessageBox.Show("not sync");
I get a messagebox instead of a write to the datatable

/Christian


Christian Westerlund wrote:

I read that a write operation on a datatable must be synchronized so I
added the following lines:
lock( dTDetailTemperatures.Rows.SyncRoot ){
// code that writes to the datatable
dT.Rows[x] = "1";
}


Christian Westerlund wrote:


I do get I an exception when I write:
If I set dT.Rows[x] = "1"
And I don't even have to scroll the datagrid to get an exception.
This is the only place where I access this datatable, I have a
connection between the grid and the table:
dG.DataSource = dT;

/Christian




Christian Westerlund wrote:


Hi!

I have a problem in my application where I have a datagrid.
the datasource is a datatable which I update every 6:th second.

foreach( Sobject s in sArrayList){

foreach( SSObject so in Sobject.array){


dT.Rows[x] =
(Myobject)so).T.Current;


}

}

I get an
"An unhandled exception of type 'System.NullReferenceException'
occurred in System.Data.dll"

when I scroll the datagrid down and upp for a minute or something
like that.

The code jumps to:
static void Main()
{
Application.Run(new FrmMyApp()); }

If I take away the dT.Rows[x] row I don't get an exception.
If I set dT.Rows[x] = "1"
I don't get any exceptions.
If I replace the dT.Rows row with this:
float t = (Myobject)so).T.Current;
I don't get an exception.

I only get an exception when I combine them.

I have added this to my code but it doesn't seem to help:
dT.BeginLoadData();
lock( sArrayList.SyncRoot){

my code

}
dT.EndLoadData();

I would appreciate every help I could get on this.
/Christian


 
Back
Top