Welcome to the Axosoft Community, Sign in | Register | Help
in Search

Dan Suceava

Everything & Nothing

DataTable.Select Bug

It seems that we've stumbled upon a bug in the DataTable.Select method.  I've been able to reproduce it but it only seems to occur when the select filter is formatted in a specific way.  Here is the code to reproduce it:

   DataSet ds = new DataSet();
   DataTable dt = new DataTable();
   dt.Columns.Add("ID", typeof(int));
   dt.Columns.Add("Name", typeof(string));
   dt.Columns.Add("Exists", typeof(bool));
   ds.Tables.Add(dt);

   DataRow dr = dt.NewRow();
   dr[0] = 1;
   dr[1] = "Name 1";
   dr[2] = true;
   dt.Rows.Add(dr);

   dr = dt.NewRow();
   dr[0] = 2;
   dr[1] = "Name 2";
   dr[2] = false;
   dt.Rows.Add(dr);

   DataRow[] drs = ds.Tables[0].Select("((ID in (1,2))) AND ((Exists = 1)) AND (Exists = 0)", "ID");

Even though this should return no rows, it actually returns one. The problem seems to be that the second condition (Exists = 1) is ignored, and only the first and third conditions get evaluated.  The only way this occurs is when both the first and second conditions are surrounded by more than one set of parenthesis.

Obviously the workaround is to get rid of the unnecessary parenthesis, however it does seem to be a bug that could cause nasty problems.

It looks like it has been fixed by Microsoft, and they have a hotfix that will fix this problem (I have verified it).  The only problem is that you cannot just download this hotfix, you have to call them up and have them e-mail it.  This is the knowledge base article: http://support.microsoft.com/default.aspx?scid=kb;en-us;891742

 

Published Monday, May 02, 2005 8:36 AM by Dan Suceava

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

TrackBack said:



Originally posted by:
Everything and Nothing
May 12, 2005 4:48 PM
 

Anonymous said:

Just experienced a similar problem:
When doing .Select(String.Format("ID={0}", someID));
no rows are returned. When I look at the XML for the DataSet, it sure is there. The strange part is that just yesterday this same piece of code was working, I must've run some update since then or I dunno WTF.

Originally posted by:
Abraham
November 22, 2005 10:55 AM
 

Anonymous said:

I have the same problem, using just the col_ID column in the expression. I've used it before, on another table, and it worked. This time it's a view that the DataTable is based on, but it should work the same way.

Originally posted by:
Eivind Gussiås Løkseth
May 9, 2006 3:49 AM
 

Anonymous said:

Forgot to mention that I have the problem on .NET 2.0, not 1.1 SP1.

Originally posted by:
Eivind Gussiås Løkseth
May 9, 2006 3:51 AM
 

Anonymous said:

I found that it was my own fault. The DataTable has all rows except the one I'm looking for, because I just changes some values in a pending transaction, that made the row disappear from the view behind the DataTable I'm running the Select-method on. How nice! :)

Originally posted by:
Eivind Gussiås Løkseth
May 9, 2006 4:07 AM
 

anonymous said:

error sql select

November 28, 2007 12:37 AM
 

anonymous said:

error sql select

November 28, 2007 12:37 AM
 

Balu B.Chand said:

try AcceptChanges() in Datatable

March 14, 2008 1:42 AM

Leave a Comment

(required) 
(optional)
(required) 
Submit



© 2002 - 2007, Axosoft, LLC. All Rights Reserved. | Privacy
Bug Tracking | Defect Tracking Videos | Help Desk Software