469,630 Members | 1,178 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,630 developers. It's quick & easy.

problem with DataTable.Select

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

The problem is that when I my code try to select an record, I get no
records.
This is the select I try:
DataTable.Select("date >= '01.11.2007 00:00:00' and date < '01.12..2007
00:00:00'");
this gives me 0 row, it should have given me 1 row

and this:
DataTable.Select("date >= '01.11.2007 00:00:00'");
gives me 3 rows, but it should have given me 1 row

what am I doing wrong here?


Jan 28 '08 #1
3 25401
On 28 Jan, 12:55, "Jeff" <do...@spam.mewrote:
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

The problem is that when I my code try to select an record, I get no
records.
This is the select I try:
DataTable.Select("date >= '01.11.2007 00:00:00' *and date < '01.12..2007
00:00:00'");
this gives me 0 row, it should have given me 1 row

and this:
DataTable.Select("date >= '01.11.2007 00:00:00'");
gives me 3 rows, but it should have given me 1 row

what am I doing wrong here?
Well, this works for me:

DataSet data = new DataSet();
data.Tables.Add(new DataTable());
data.Tables[0].Columns.Add("ADate", Type.GetType("System.DateTime"));
data.Tables[0].Rows.Add(new object[]{DateTime.Parse("15/09/2007")});
data.Tables[0].Rows.Add(new object[]{DateTime.Parse("15/10/2007")});
data.Tables[0].Rows.Add(new object[]{DateTime.Parse("15/11/2007")});

DataRow[] rows = data.Tables[0].Select("ADate >= '01/11/2007' and
ADate < '01/12/2007'");
Console.WriteLine(rows.Length.ToString()); //returns 1
rows = data.Tables[0].Select("ADate '01/11/2007'");
Console.WriteLine(rows.Length.ToString()); //returns 1
but
DataSet data = new DataSet();
data.Tables.Add(new DataTable());
data.Tables[0].Columns.Add("ADate", Type.GetType("System.DateTime"));
data.Tables[0].Rows.Add(new object[]{DateTime.Parse("15/09/2007")});
data.Tables[0].Rows.Add(new object[]{DateTime.Parse("15/10/2007")});
data.Tables[0].Rows.Add(new object[]{DateTime.Parse("15/11/2007")});

DataRow[] rows = data.Tables[0].Select("ADate >= '11/01/2007' and
ADate < '12/01/2007'");
Console.WriteLine(rows.Length.ToString()); //returns 0
rows = data.Tables[0].Select("ADate '11/01/2007'");
Console.WriteLine(rows.Length.ToString()); //returns 3
gives the results you get. Your dates are being interpreted as MM/DD
not DD/MM.
Jan 28 '08 #2
Hi,
Most probably those are not valid dates , could you try it without the time
component?

--
Ignacio Machin
http://www.laceupsolutions.com
Mobile & warehouse Solutions.
"Jeff" <do***@spam.mewrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
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

The problem is that when I my code try to select an record, I get no
records.
This is the select I try:
DataTable.Select("date >= '01.11.2007 00:00:00' and date < '01.12..2007
00:00:00'");
this gives me 0 row, it should have given me 1 row

and this:
DataTable.Select("date >= '01.11.2007 00:00:00'");
gives me 3 rows, but it should have given me 1 row

what am I doing wrong here?


Jan 28 '08 #3
Jeff,

It's pretty obvious that it is expecting a date in YYYY-MM-DD HH:mm:ss
format. I suggest you try formatting your date using that format, and not
the format based on the current culture (also, try using the date literal,
the pound sign, i.e. '#').
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Jeff" <do***@spam.mewrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
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

The problem is that when I my code try to select an record, I get no
records.
This is the select I try:
DataTable.Select("date >= '01.11.2007 00:00:00' and date < '01.12..2007
00:00:00'");
this gives me 0 row, it should have given me 1 row

and this:
DataTable.Select("date >= '01.11.2007 00:00:00'");
gives me 3 rows, but it should have given me 1 row

what am I doing wrong here?


Jan 28 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Saso Zagoranski | last post: by
reply views Thread by Chris Ericoli | last post: by
4 posts views Thread by The Alchemist | last post: by
3 posts views Thread by emailtonitin | last post: by
30 posts views Thread by dbuchanan | last post: by
4 posts views Thread by Aryan | last post: by
6 posts views Thread by Pete Wittig | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.