473,396 Members | 1,898 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 25636
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Mullin Yu | last post by:
i have a stored procedure at sql server 2k. which will update records and select result from temp table. if i use SqlConnection class, and i do both. but, if i use OleDbConnection class, i can...
10
by: Saso Zagoranski | last post by:
hi, this is not actually a C# problem but since this is the only newsgroup I follow I decided to post my question here (please tell me where to post this next time if you think this post...
0
by: Chris Ericoli | last post by:
Hi, I am working with an 'in session' ado dataset with an asp.net application. My dataset is comprised of two tables, one of which maintains a few calculated datacolumns. For some reason these...
4
by: The Alchemist | last post by:
I am having a problem with a dynamically-generated Datagrid. It is important to point out that this problem does not exist with a design-time created Datagrid, but only with a dynamically generated...
3
by: emailtonitin | last post by:
Hi, I am having a problem with the default sorting mechanism employed by the datatable.select method - I have a datatable having rows (simplified for clarity) - name ----- c a
30
by: dbuchanan | last post by:
ComboBox databindng Problem == How the ComboBox is setup and used: My comboBox is populated by a lookup table. The ValueMember is the lookup table's Id and the DisplayMember is the text from a...
4
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,...
6
by: Pete Wittig | last post by:
Hi, I have a DataTable and I want to get a subset of the rows within it. I use the Select method to get my subset and the results are in a DataRow. I want to put those Rows back into a...
0
by: rupalirane07 | last post by:
Both grids displays fine. But the problem is only parent datagrid sorting works fine but when i clik on child datagrid for sorting it gives me error: NullReferenceException error Any...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.