Exception in DataTable.Select

L

Latinneo

I receive the following error when I try to select data rows from a
data table in c# using the method DataTable.Select....

Exception:
Object reference not set to an instance of an object.

Stack:
System.Web.HttpUnhandledException: Exception of type
System.Web.HttpUnhandledException was thrown. --->
System.NullReferenceException: Object reference not set to an instance
of an object.
at System.Data.Select.FindClosestCandidateIndex()
at System.Data.Select.SelectRows()
at System.Data.DataTable.Select(String filterExpression, String
sort)
at CustomControls.SystemControl.InitializeComponent() in
C:\WebProjects\CommonProjects_Solution\CustomControls\SystemControl.cs:line
81
at CustomControls.SystemControl.OnInit(EventArgs e) in
C:\WebProjects\CommonProjects_Solution\CustomControls\SystemControl.cs:line
60
at System.Web.UI.Control.InitRecursive(Control namingContainer)
at System.Web.UI.Control.InitRecursive(Control namingContainer)
at System.Web.UI.Control.InitRecursive(Control namingContainer)
at System.Web.UI.Page.ProcessRequestMain()
--- End of inner exception stack trace ---
at System.Web.UI.Page.HandleError(Exception e)
at System.Web.UI.Page.ProcessRequestMain()
at System.Web.UI.Page.ProcessRequest()
at System.Web.UI.Page.ProcessRequest(HttpContext context)
at System.Web.CallHandlerExecutionStep.System.Web.HttpApplication+IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step,
Boolean& completedSynchronously)


The application is multi-threaded and reads the same data from
multiple threads, but no modification is made to the data. According
to the MSDN DataTable is thread-safe when reading.

This error does not always occur, it seems like there is some
threading problem with the DataTable... Has anyone experienced similar
behaviour? Any help or idea's will be really appreciated!
 
W

William Ryan eMVP

I haven't had this problem, but if the table is initialized, it's next to
impossible to tell from just this code. I'd wrap the code in exception
handlers, do a Debug.Assert(Not myDataTable Is Nothing) before the place
where I think it's happening and try to track it down from there.

Can you post the .Select code?
 
O

Oren Ferrari

I am having this issue all the time. I get exceptions related to this
issue fairly frequently. I can't be sure why it is happening, but I
think it might be a thread safe issue.

The behavior is basically that one or more rows in the returned array
is null. Which eventually throws an exception.

I have even seen behavior which a row disappears to null even after
acquiring valid data.

Is anyone else seeing this happen?
 
C

Christian Boult

We are getting the exact same problem when about 25 simultaneous select in a
cached DataTable.
Then after it occurs once, anybody trying to select from the datatable will
always get the problem until we reload it.
I woul also appreciate if anybody with info or idea on this to post it.
Thanks


Christian.
 
C

Christian Boult

Turns out the problem was the use of DataView and setting RowFilter on that
dataview. That apparently messes up the internal indexes on the the
DataTable

Instead I took out all that code and replace it with DataTable.Select(
filter ) and that fixed it.

Chris.
 

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