DataTable

  • Thread starter Thread starter Wal Turner
  • Start date Start date
W

Wal Turner

I am using the System.Data.DataTable class which I have heard may display
some unusual behaviour.

I am doing

DataRow[] dr = dataTable.Select(sql);

The sql in this instance doesnt matter - what is important is that dr.Length
is greater than 0, implying there is at least one result.
However I discovered that sometimes this method was returning dr.Length = 1
when I thought it should return 0 rows. In fact, the dataTable contents
reflected it returning 0 rows but it chose to return one anyway!

Further inspection showed this DataRow to be null, ie dr[0] == null

Has anyone come across this similar problem?

Regards

Wal
 
Hi,
I am using the System.Data.DataTable class which I have heard may display
some unusual behaviour.
Like?

I am doing

DataRow[] dr = dataTable.Select(sql);

The sql in this instance doesnt matter -

In general it DOES , the sql is not a SELECT clause from sql, but a filter
expression ( like the WHERE clause in SQL )
what is important is that dr.Length
is greater than 0, implying there is at least one result.
However I discovered that sometimes this method was returning dr.Length = 1
when I thought it should return 0 rows. In fact, the dataTable contents
reflected it returning 0 rows but it chose to return one anyway!

Further inspection showed this DataRow to be null, ie dr[0] == null

Has anyone come across this similar problem?

Nop, please try to post a complete example where this happen, if possible
with the table definition, etc it may be a bug after all.


cheers,
 
Thank you for your reply. Unfortunately I cannot give a specific example as
the bug seems to occur randomly. The select statement (or WHERE clause) is a
simple filter, eg "TradeID=" + x

which works as expected most of the time. I guess the unusual thing here is
that dataTable.Select( ) is returning a null row - I've read the
documentation for DataTable and it would seem by definition if its returning
a row then that row can't be null!

I guess the (sql) analogy here is doing a select statement and having
count(*) = 1 but then when you actually get the row in question it doesnt
exist!

Regards

Wal



Ignacio Machin ( .NET/ C# MVP ) said:
Hi,
I am using the System.Data.DataTable class which I have heard may display
some unusual behaviour.
Like?

I am doing

DataRow[] dr = dataTable.Select(sql);

The sql in this instance doesnt matter -

In general it DOES , the sql is not a SELECT clause from sql, but a filter
expression ( like the WHERE clause in SQL )
what is important is that dr.Length
is greater than 0, implying there is at least one result.
However I discovered that sometimes this method was returning dr.Length
=
1
when I thought it should return 0 rows. In fact, the dataTable contents
reflected it returning 0 rows but it chose to return one anyway!

Further inspection showed this DataRow to be null, ie dr[0] == null

Has anyone come across this similar problem?

Nop, please try to post a complete example where this happen, if possible
with the table definition, etc it may be a bug after all.


cheers,
 
Have you installed the .NET SP1???

Because I've encountered exactly the same you're saying, after installing
SP1. It happened in my string-translation library which I haven't touched
for at least two years now. But it happened just once, and I wasn't able to
reproduce it.

Stefan

Wal Turner said:
Thank you for your reply. Unfortunately I cannot give a specific example
as
the bug seems to occur randomly. The select statement (or WHERE clause) is
a
simple filter, eg "TradeID=" + x

which works as expected most of the time. I guess the unusual thing here
is
that dataTable.Select( ) is returning a null row - I've read the
documentation for DataTable and it would seem by definition if its
returning
a row then that row can't be null!

I guess the (sql) analogy here is doing a select statement and having
count(*) = 1 but then when you actually get the row in question it doesnt
exist!

Regards

Wal



"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us>
wrote
in message news:[email protected]...
Hi,
I am using the System.Data.DataTable class which I have heard may display
some unusual behaviour.
Like?

I am doing

DataRow[] dr = dataTable.Select(sql);

The sql in this instance doesnt matter -

In general it DOES , the sql is not a SELECT clause from sql, but a filter
expression ( like the WHERE clause in SQL )
what is important is that dr.Length
is greater than 0, implying there is at least one result.
However I discovered that sometimes this method was returning dr.Length
=
1
when I thought it should return 0 rows. In fact, the dataTable contents
reflected it returning 0 rows but it chose to return one anyway!

Further inspection showed this DataRow to be null, ie dr[0] == null

Has anyone come across this similar problem?

Nop, please try to post a complete example where this happen, if possible
with the table definition, etc it may be a bug after all.


cheers,
 
I have no service pack installed...still a mystery...

Stefan Simek said:
Have you installed the .NET SP1???

Because I've encountered exactly the same you're saying, after installing
SP1. It happened in my string-translation library which I haven't touched
for at least two years now. But it happened just once, and I wasn't able to
reproduce it.

Stefan

Wal Turner said:
Thank you for your reply. Unfortunately I cannot give a specific example
as
the bug seems to occur randomly. The select statement (or WHERE clause) is
a
simple filter, eg "TradeID=" + x

which works as expected most of the time. I guess the unusual thing here
is
that dataTable.Select( ) is returning a null row - I've read the
documentation for DataTable and it would seem by definition if its
returning
a row then that row can't be null!

I guess the (sql) analogy here is doing a select statement and having
count(*) = 1 but then when you actually get the row in question it doesnt
exist!

Regards

Wal



"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us>
wrote
in message news:[email protected]...
Hi,

I am using the System.Data.DataTable class which I have heard may display
some unusual behaviour.

Like?

I am doing

DataRow[] dr = dataTable.Select(sql);

The sql in this instance doesnt matter -

In general it DOES , the sql is not a SELECT clause from sql, but a filter
expression ( like the WHERE clause in SQL )

what is important is that dr.Length
is greater than 0, implying there is at least one result.
However I discovered that sometimes this method was returning
dr.Length
=
1
when I thought it should return 0 rows. In fact, the dataTable contents
reflected it returning 0 rows but it chose to return one anyway!

Further inspection showed this DataRow to be null, ie dr[0] == null

Has anyone come across this similar problem?

Nop, please try to post a complete example where this happen, if possible
with the table definition, etc it may be a bug after all.


cheers,
 
Back
Top