473,657 Members | 2,825 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DataTable.Selec t() is bugged?

Hi.

I'm trying to make a criteria string to use in Select() method of a datatable, searching for a date, but it is apparently not working!

In one of my tests, I have a datatable with 1 row and a field containing the following value (extracted from Immediate Window):

?dtbSample.Rows (0).Item("COM_S TARTDATE")
#5/8/2006 9:00:00 AM# {Date}
Date: #5/8/2006 9:00:00 AM#
(for better understand, consider this date as '2006/05/08')
Then, I test a criterium to DON'T show that row, using this:
arrRows = dtbSample.Selec t("COM_STARTDAT E >= '2006/05/09'")

Now, look the results in immediate window:
?arrRows.Length
1

!!!!!!
The Select() is returning a DataRow with a date less than the specified criterium, which is requiring a date higher than existing in the DataTable!!
In resume, '2006/05/08' is less than "COM_STARTD ATE >= '2006/05/09'", but is returning like if '2006/05/08' is higher.

Someone already noticed that behaviour? There is a way to fix it?
Cesar

ps.:
For you know, I tryied to build criteria like below and still is returning row (not working):
("COM_STARTD ATE >= #'2006/05/09#") 'yyyy/MM/dd and #
("COM_STARTD ATE >= '05/09/2006'") 'MM/dd/yyyy
("COM_STARTD ATE >= '" & TheDate.ToStrin g & "'") 'a Date datatype
("COM_STARTD ATE >= #05/09/2006#") 'MM/dd/yyyy and #
("COM_STARTD ATE >= #May/09/2006#") 'MMM/dd/yyyy and #

I repeat, these don't works!! They are returning the row. :^P


May 10 '06 #1
6 4682
OUCH! Found it... the Select() method by default, searches only for commited data.... and my DataRow was not yet commited by the AcceptChanges() method.

Then, to fix it, i should use:
arrRows = dtbSample.Selec t("COM_STARTDAT E >= #May/09/2006#", "", DataViewRowStat e.ModifiedCurre nt)

The third parameter now makes the method works like I want.

[]s
Cesar



"ronchese" <info(a)carsoft net.com.br> wrote in message news:eu******** *****@TK2MSFTNG P02.phx.gbl...
Hi.

I'm trying to make a criteria string to use in Select() method of a datatable, searching for a date, but it is apparently not working!

In one of my tests, I have a datatable with 1 row and a field containing the following value (extracted from Immediate Window):

?dtbSample.Rows (0).Item("COM_S TARTDATE")
#5/8/2006 9:00:00 AM# {Date}
Date: #5/8/2006 9:00:00 AM#
(for better understand, consider this date as '2006/05/08')
Then, I test a criterium to DON'T show that row, using this:
arrRows = dtbSample.Selec t("COM_STARTDAT E >= '2006/05/09'")

Now, look the results in immediate window:
?arrRows.Length
1

!!!!!!
The Select() is returning a DataRow with a date less than the specified criterium, which is requiring a date higher than existing in the DataTable!!
In resume, '2006/05/08' is less than "COM_STARTD ATE >= '2006/05/09'", but is returning like if '2006/05/08' is higher.

Someone already noticed that behaviour? There is a way to fix it?
Cesar

ps.:
For you know, I tryied to build criteria like below and still is returning row (not working):
("COM_STARTD ATE >= #'2006/05/09#") 'yyyy/MM/dd and #
("COM_STARTD ATE >= '05/09/2006'") 'MM/dd/yyyy
("COM_STARTD ATE >= '" & TheDate.ToStrin g & "'") 'a Date datatype
("COM_STARTD ATE >= #05/09/2006#") 'MM/dd/yyyy and #
("COM_STARTD ATE >= #May/09/2006#") 'MMM/dd/yyyy and #

I repeat, these don't works!! They are returning the row. :^P


May 10 '06 #2
Cesar,
I suspect that '2006/05/09' is not being translated properly.

Try:

arrRows = dtbSample.Selec t("COM_STARTDAT E >= #05/09/2006#")
As Date values in DataSet expressions need to be delimited by #.

http://msdn.microsoft.com/library/de...ssiontopic.asp

I believe the date values are in m/d/y format.
Something like:

Dim table As New DataTable
table.Columns.A dd("COM_STARTDA TE", GetType(DateTim e))
table.Rows.Add( #5/8/2006 9:00:00 AM#)

Dim rows() As DataRow = table.Select("C OM_STARTDATE >=
#05/09/2006#")
--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"ronchese" <info(a)carsoft net.com.br> wrote in message
news:eu******** *****@TK2MSFTNG P02.phx.gbl...
Hi.

I'm trying to make a criteria string to use in Select() method of a
datatable, searching for a date, but it is apparently not working!

In one of my tests, I have a datatable with 1 row and a field containing the
following value (extracted from Immediate Window):

?dtbSample.Rows (0).Item("COM_S TARTDATE")
#5/8/2006 9:00:00 AM# {Date}
Date: #5/8/2006 9:00:00 AM#
(for better understand, consider this date as '2006/05/08')
Then, I test a criterium to DON'T show that row, using this:
arrRows = dtbSample.Selec t("COM_STARTDAT E >= '2006/05/09'")

Now, look the results in immediate window:
?arrRows.Length
1

!!!!!!
The Select() is returning a DataRow with a date less than the specified
criterium, which is requiring a date higher than existing in the DataTable!!
In resume, '2006/05/08' is less than "COM_STARTD ATE >= '2006/05/09'", but is
returning like if '2006/05/08' is higher.

Someone already noticed that behaviour? There is a way to fix it?
Cesar

ps.:
For you know, I tryied to build criteria like below and still is returning
row (not working):
("COM_STARTD ATE >= #'2006/05/09#") 'yyyy/MM/dd and #
("COM_STARTD ATE >= '05/09/2006'") 'MM/dd/yyyy
("COM_STARTD ATE >= '" & TheDate.ToStrin g & "'") 'a Date datatype
("COM_STARTD ATE >= #05/09/2006#") 'MM/dd/yyyy and #
("COM_STARTD ATE >= #May/09/2006#") 'MMM/dd/yyyy and #

I repeat, these don't works!! They are returning the row. :^P

May 10 '06 #3
I tryied # also, like showed in PS area, at end of e-mail :D
ps.:
For you know, I tryied to build criteria like below and still is returning
row (not working):


("COM_STARTD ATE >= #'2006/05/09#") 'yyyy/MM/dd and #
("COM_STARTD ATE >= '05/09/2006'") 'MM/dd/yyyy
("COM_STARTD ATE >= '" & TheDate.ToStrin g & "'") 'a Date datatype
("COM_STARTD ATE >= #05/09/2006#") 'MM/dd/yyyy and #
("COM_STARTD ATE >= #May/09/2006#") 'MMM/dd/yyyy and #
But the problem was the rows not commited, and the Select() only searches in commited data.
I posted the solution in a other reply.

Thanks anyway, for response.

[]s
Cesar

"Jay B. Harlow [MVP - Outlook]" <Ja************ @tsbradley.net> wrote in message news:%2******** ********@TK2MSF TNGP05.phx.gbl. .. Cesar,
I suspect that '2006/05/09' is not being translated properly.

Try:

arrRows = dtbSample.Selec t("COM_STARTDAT E >= #05/09/2006#")


As Date values in DataSet expressions need to be delimited by #.

http://msdn.microsoft.com/library/de...ssiontopic.asp

I believe the date values are in m/d/y format.


Something like:

Dim table As New DataTable
table.Columns.A dd("COM_STARTDA TE", GetType(DateTim e))
table.Rows.Add( #5/8/2006 9:00:00 AM#)

Dim rows() As DataRow = table.Select("C OM_STARTDATE >=
#05/09/2006#")


--
Hope this helps
Jay B. Harlow [MVP - Outlook]
.NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


"ronchese" <info(a)carsoft net.com.br> wrote in message
news:eu******** *****@TK2MSFTNG P02.phx.gbl...
Hi.

I'm trying to make a criteria string to use in Select() method of a
datatable, searching for a date, but it is apparently not working!

In one of my tests, I have a datatable with 1 row and a field containing the
following value (extracted from Immediate Window):

?dtbSample.Rows (0).Item("COM_S TARTDATE")
#5/8/2006 9:00:00 AM# {Date}
Date: #5/8/2006 9:00:00 AM#
(for better understand, consider this date as '2006/05/08')


Then, I test a criterium to DON'T show that row, using this:
arrRows = dtbSample.Selec t("COM_STARTDAT E >= '2006/05/09'")

Now, look the results in immediate window:
?arrRows.Length
1

!!!!!!
The Select() is returning a DataRow with a date less than the specified
criterium, which is requiring a date higher than existing in the DataTable!!
In resume, '2006/05/08' is less than "COM_STARTD ATE >= '2006/05/09'", but is
returning like if '2006/05/08' is higher.

Someone already noticed that behaviour? There is a way to fix it?


Cesar

ps.:
For you know, I tryied to build criteria like below and still is returning
row (not working):


("COM_STARTD ATE >= #'2006/05/09#") 'yyyy/MM/dd and #
("COM_STARTD ATE >= '05/09/2006'") 'MM/dd/yyyy
("COM_STARTD ATE >= '" & TheDate.ToStrin g & "'") 'a Date datatype
("COM_STARTD ATE >= #05/09/2006#") 'MM/dd/yyyy and #
("COM_STARTD ATE >= #May/09/2006#") 'MMM/dd/yyyy and #

I repeat, these don't works!! They are returning the row. :^P




May 10 '06 #4
Hmmm... After some testes, I noticed that the value DataViewRowStat e.CurrentRows works better than the previous I told.

Example:
arrRows = dtbSample.Selec t(strCrit, "", DataViewRowStat e.CurrentRows)

[]s
Cesar

"ronchese" <info(a)carsoft net.com.br> wrote in message news:u9******** ******@TK2MSFTN GP04.phx.gbl...
OUCH! Found it... the Select() method by default, searches only for commited data.... and my DataRow was not yet commited by the AcceptChanges() method.

Then, to fix it, i should use:
arrRows = dtbSample.Selec t("COM_STARTDAT E >= #May/09/2006#", "", DataViewRowStat e.ModifiedCurre nt)

The third parameter now makes the method works like I want.

[]s
Cesar



"ronchese" <info(a)carsoft net.com.br> wrote in message news:eu******** *****@TK2MSFTNG P02.phx.gbl...
Hi.

I'm trying to make a criteria string to use in Select() method of a datatable, searching for a date, but it is apparently not working!

In one of my tests, I have a datatable with 1 row and a field containing the following value (extracted from Immediate Window):

?dtbSample.Rows (0).Item("COM_S TARTDATE")
#5/8/2006 9:00:00 AM# {Date}
Date: #5/8/2006 9:00:00 AM#
(for better understand, consider this date as '2006/05/08')
Then, I test a criterium to DON'T show that row, using this:
arrRows = dtbSample.Selec t("COM_STARTDAT E >= '2006/05/09'")

Now, look the results in immediate window:
?arrRows.Length
1

!!!!!!
The Select() is returning a DataRow with a date less than the specified criterium, which is requiring a date higher than existing in the DataTable!!
In resume, '2006/05/08' is less than "COM_STARTD ATE >= '2006/05/09'", but is returning like if '2006/05/08' is higher.

Someone already noticed that behaviour? There is a way to fix it?
Cesar

ps.:
For you know, I tryied to build criteria like below and still is returning row (not working):
("COM_STARTD ATE >= #'2006/05/09#") 'yyyy/MM/dd and #
("COM_STARTD ATE >= '05/09/2006'") 'MM/dd/yyyy
("COM_STARTD ATE >= '" & TheDate.ToStrin g & "'") 'a Date datatype
("COM_STARTD ATE >= #05/09/2006#") 'MM/dd/yyyy and #
("COM_STARTD ATE >= #May/09/2006#") 'MMM/dd/yyyy and #

I repeat, these don't works!! They are returning the row. :^P


May 10 '06 #5
Working more, I got another problems with some other uses for select()... After break the head a bit more, I found that DataBindings was the root for causing all the troubles. Then, after I set:

BindingContext( dtb).SuspendLay out()

... when the form closes, everything work like nothing was happened.
And then, I even dont needed that 3rd parameter in the Select() commands I used. Rewrote everything again. :D

[]s
Cesar
"ronchese" <info(a)carsoft net.com.br> wrote in message news:Og******** ******@TK2MSFTN GP03.phx.gbl...
Hmmm... After some testes, I noticed that the value DataViewRowStat e.CurrentRows works better than the previous I told.

Example:
arrRows = dtbSample.Selec t(strCrit, "", DataViewRowStat e.CurrentRows)

[]s
Cesar

"ronchese" <info(a)carsoft net.com.br> wrote in message news:u9******** ******@TK2MSFTN GP04.phx.gbl...
OUCH! Found it... the Select() method by default, searches only for commited data.... and my DataRow was not yet commited by the AcceptChanges() method.

Then, to fix it, i should use:
arrRows = dtbSample.Selec t("COM_STARTDAT E >= #May/09/2006#", "", DataViewRowStat e.ModifiedCurre nt)

The third parameter now makes the method works like I want.

[]s
Cesar



"ronchese" <info(a)carsoft net.com.br> wrote in message news:eu******** *****@TK2MSFTNG P02.phx.gbl...
Hi.

I'm trying to make a criteria string to use in Select() method of a datatable, searching for a date, but it is apparently not working!

In one of my tests, I have a datatable with 1 row and a field containing the following value (extracted from Immediate Window):

?dtbSample.Rows (0).Item("COM_S TARTDATE")
#5/8/2006 9:00:00 AM# {Date}
Date: #5/8/2006 9:00:00 AM#
(for better understand, consider this date as '2006/05/08')
Then, I test a criterium to DON'T show that row, using this:
arrRows = dtbSample.Selec t("COM_STARTDAT E >= '2006/05/09'")

Now, look the results in immediate window:
?arrRows.Length
1

!!!!!!
The Select() is returning a DataRow with a date less than the specified criterium, which is requiring a date higher than existing in the DataTable!!
In resume, '2006/05/08' is less than "COM_STARTD ATE >= '2006/05/09'", but is returning like if '2006/05/08' is higher.

Someone already noticed that behaviour? There is a way to fix it?
Cesar

ps.:
For you know, I tryied to build criteria like below and still is returning row (not working):
("COM_STARTD ATE >= #'2006/05/09#") 'yyyy/MM/dd and #
("COM_STARTD ATE >= '05/09/2006'") 'MM/dd/yyyy
("COM_STARTD ATE >= '" & TheDate.ToStrin g & "'") 'a Date datatype
("COM_STARTD ATE >= #05/09/2006#") 'MM/dd/yyyy and #
("COM_STARTD ATE >= #May/09/2006#") 'MMM/dd/yyyy and #

I repeat, these don't works!! They are returning the row. :^P


May 10 '06 #6
Ronchese,

That the Select is buggy is in my idea not even testable because the lack of documentation around the Expression.

However, AFAIK has a date in the select in VB to be the USA date literal as you have used in your example. The Expression is AFAIK totaly based on USA behaviour.

I hope this helps a little bit.

Cor
"ronchese" <info(a)carsoft net.com.br> schreef in bericht news:eu******** *****@TK2MSFTNG P02.phx.gbl...
Hi.

I'm trying to make a criteria string to use in Select() method of a datatable, searching for a date, but it is apparently not working!

In one of my tests, I have a datatable with 1 row and a field containing the following value (extracted from Immediate Window):

?dtbSample.Rows (0).Item("COM_S TARTDATE")
#5/8/2006 9:00:00 AM# {Date}
Date: #5/8/2006 9:00:00 AM#
(for better understand, consider this date as '2006/05/08')
Then, I test a criterium to DON'T show that row, using this:
arrRows = dtbSample.Selec t("COM_STARTDAT E >= '2006/05/09'")

Now, look the results in immediate window:
?arrRows.Length
1

!!!!!!
The Select() is returning a DataRow with a date less than the specified criterium, which is requiring a date higher than existing in the DataTable!!
In resume, '2006/05/08' is less than "COM_STARTD ATE >= '2006/05/09'", but is returning like if '2006/05/08' is higher.

Someone already noticed that behaviour? There is a way to fix it?
Cesar

ps.:
For you know, I tryied to build criteria like below and still is returning row (not working):
("COM_STARTD ATE >= #'2006/05/09#") 'yyyy/MM/dd and #
("COM_STARTD ATE >= '05/09/2006'") 'MM/dd/yyyy
("COM_STARTD ATE >= '" & TheDate.ToStrin g & "'") 'a Date datatype
("COM_STARTD ATE >= #05/09/2006#") 'MM/dd/yyyy and #
("COM_STARTD ATE >= #May/09/2006#") 'MMM/dd/yyyy and #

I repeat, these don't works!! They are returning the row. :^P


May 10 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
8114
by: Luc | last post by:
I am using Visual Studio 2003 and am getting lousy performance after using a datatable select and then trying to assign a value to a column of the row that was found: DataTable dt = new DataTable(); dt.Columns.Add("Number", System.Type.GetType("System.Int32")); dt.Columns.Add("Value", System.Type.GetType("System.Double")); for(int i=0;i<2000;i++) {
4
2562
by: Kris Rudin | last post by:
I am displaying a table of information on a web page, using an asp:table that I populate dynamically. On this page I give the user the options to group the rows by certain fields, and/or filter the contents on certain fields. The grouping/filtering is "remembered" for each user via a cookie. The problem is works like this: User A applies a filter on Project Manager. User B filters by Department. User B groups by Project Manager (NOTE -...
2
40046
by: Marcel Hug | last post by:
Hi NG! With a Inner-Join SQL I get my datas in a DataSet. In the table are the column Entry and Version. Like this: Entry Version 1 1 1 2 1 3
7
14990
by: wk6pack | last post by:
Hi, How do I check datatable.select(filter) in the following: for each dtrow in datatable.select(filter) .... next I've also tried:
4
7109
by: Aryan | last post by:
Hi, I am having problem with DataTable.Select() method. I am using ASP.NET 2.0. I have DataSet which reads data from XML file using DataSet.ReadXML(). Now this dataset has various datatable, created by XML file. I am taking one of the datatable from this dataset and want to filter on that datatable using Select() method. Now here the problem start, like when I pass multiple "And" clause in
1
5729
by: Maxwell2006 | last post by:
Hi, I am working with strongly typed datatables. What is the most efficient way to build a new DataTAble based on the result of DataTable.Select? At this point I use a foreach loop to do the work manually. I am looking for an automated way. Thank you, Max
5
20861
by: Manikandan | last post by:
Hi, I have a datatable with rows. When I used datatable.select with values it is working properly, But when I use the select with variables it is not working. I tried with putting '(single quote),"" '(double quote) and many combination, it is not returning any rows Sample code for demonstartion DataTable aDataTable = new DataTable(); aDataTable.Columns.Add("s1", typeof(string)); aDataTable.Columns.Add("s2", typeof(string));
4
6236
by: Massimo | last post by:
Hi to All, i'm using C# in .NET 2.0 and i have a DataTable A with a column of type TimeSpan used to store HOUR info. I'm trying to filter my DataTable A selecting only rows that have the column HOUR .... if i try to Call A.Select( " HOUR '10:30:00' " ) i receive an error ( cannot compare TimeSpan with String ...) if i try to call A.Select ( " HOUR 10:30:00 " ) i receive an error ( invalid token : )
3
25680
by: Jeff | last post by:
hey ..NET 2.0 I have a datatable which consist of 3 columns (int, date, value). This DataTable have 3 rows, the values of the "date" ("date" column is of datetime datatype) column is: 2007-09-15 00:00:00.000 2007-10-15 00:00:00.000 2007-11-15 00:00:00.000
3
2821
by: Nuno Magalhaes | last post by:
Hello, I have a DataTable in which the items are of type MyClass. How can I use Select to compare a MyClass instance with the DataTable? Is there any overriden method (like the ToString()) to use it on Select? Thank you, Nuno Magalhães.
0
8403
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8316
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8737
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8509
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6174
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5636
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4327
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1967
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1730
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.