System.Data.Select.Evaluate NullReferenceException?

J

Joshua Coady

Hello,

I am experiencing an exception that is thrown from within the
System.Data.Select.Evaluate method.

I am updating a data table inside of a loop that could update, insert,
and/or delete rows.

When I use this select statement I get the exception included at the
bottom of this message (but only if MyDataTable has modified rows with
MyFKID = 12):

#1 DataRow[] rows = myStronglyTypedDataSet.MyDataTable.Select(
"Parent(MyRelationName).LabelField = 'My Label' AND MyFKID =
12");

If I use a data view it works, no exception is thrown and it works
fine:

#2 myStronglyTypedDataSet.MyDataTable.DefaultView.RowFilter
= "Parent(MyRelationName).LabelField = 'My Label' AND MyFKID =
12";

Also, if I put a breakpoint on #1 and enter some things into the
watch, these all work as expected (when the select does not have any
results, it return an empty array, otherwise the arrays returned have
the correct number of values):

// There is no row with MyFKID = 12999
DataRow[] rows = myStronglyTypedDataSet.MyDataTable.Select(
"Parent(MyRelationName).LabelField = 'My Label' AND MyFKID =
12999");

DataRow[] rows = myStronglyTypedDataSet.MyDataTable.Select(
"Parent(MyRelationName).LabelField = 'My Label' OR MyFKID =
12");

DataRow[] rows = myStronglyTypedDataSet.MyDataTable.Select(
"MyFKID = 12");

// This row does exist, but it is unmodified
DataRow[] rows = myStronglyTypedDataSet.MyDataTable.Select(
"Parent(MyRelationName).LabelField = 'My Label' AND MyFKID =
1");

// There is no LabelField = 'My Label X'
DataRow[] rows = myStronglyTypedDataSet.MyDataTable.Select(
"Parent(MyRelationName).LabelField = 'My Label X' AND MyFKID =
12");

But if I put in the statement as it is in code (#1), I get the null
ref exception. I have experienced sometimes when I am editing
something else in the watch, that the value of #1 in the watch will
change from the exception to the expected value. Then, if I continue
and run the code, it all works fine.

I have also tried the code with different DataViewRosState valuues,
but with no luck.

Anyways, thanks in advance for the help, and the exception is included
below.

Josh

Stack Trace:
[NullReferenceException: Object reference not set to an instance of an
object.]
System.Data.Select.Evaluate(Int32 record) +147
System.Data.Select.FindFirstMatchingRecord() +55
System.Data.Select.GetBinaryFilteredRecords() +101
System.Data.Select.SelectRows() +389
System.Data.DataTable.Select(String filterExpression, String sort,
DataViewRowState recordStates) +43
<my calling method>
 

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