DataTable Select

Discussion in 'ASP .Net' started by VK, May 10, 2005.

  1. VK

    VK Guest

    Hello,

    I have a dataset which has one datatable in it. The dt
    has over 3000 rows in it. Now I would like to get the rows
    where the StartDate is 15 Feb 2005, so I did the following:

    ds.Tables(0).Select("StartDate = '15/02/2005'")

    However this returns me only 3 rows. I have tried other
    possiblities like:

    ds.Tables(0).Select("StartDate = '15 Feb 2005'")
    ds.Tables(0).Select("StartDate = #15/02/2005#")
    ds.Tables(0).Select("StartDate = '15/2/2005'")

    But all of them returns only 3 rows. I know that there are
    more then 3 rows for that date. I cheked the data from the
    dbase and compared the rows with the dt and found the
    dates, but I am not getting the expected result when I use
    Select.

    Can somebody help me please?

    Thanks
     
    VK, May 10, 2005
    #1
    1. Advertising

  2. VK

    Karl Seguin Guest

    Just a guess but maybe some of the dates have times in them so they aren't
    equal to exactly 15/02/2005

    why not try > 15/02/2005 and < 16/02/2005 or something...

    Karl

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/ - New and Improved (yes, the popup is
    annoying)
    http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
    come!)
    "VK" <> wrote in message
    news:1f0601c5556b$d9c38be0$...
    > Hello,
    >
    > I have a dataset which has one datatable in it. The dt
    > has over 3000 rows in it. Now I would like to get the rows
    > where the StartDate is 15 Feb 2005, so I did the following:
    >
    > ds.Tables(0).Select("StartDate = '15/02/2005'")
    >
    > However this returns me only 3 rows. I have tried other
    > possiblities like:
    >
    > ds.Tables(0).Select("StartDate = '15 Feb 2005'")
    > ds.Tables(0).Select("StartDate = #15/02/2005#")
    > ds.Tables(0).Select("StartDate = '15/2/2005'")
    >
    > But all of them returns only 3 rows. I know that there are
    > more then 3 rows for that date. I cheked the data from the
    > dbase and compared the rows with the dt and found the
    > dates, but I am not getting the expected result when I use
    > Select.
    >
    > Can somebody help me please?
    >
    > Thanks
     
    Karl Seguin, May 10, 2005
    #2
    1. Advertising

  3. VK

    VK Guest

    Thanks for the reply

    I tried:

    ds.tables(0).Select("StartDate > #15/02/2005# and
    StartDate < #16/02/2005#")

    which returned:

    Run-time exception thrown : System.FormatException -
    String was not recognized as a valid DateTime.

    I tried:

    ds.tables(0).Select("StartDate > #2/15/2005# and StartDate
    < #2/16/2005#")

    which returned 0 rows

    Also tried:

    ds.tables(0).Select("StartDate > '15/02/2005' and
    StartDate < '16/02/2005'")

    which returns also 0 rows.

    When I check a row, which has the date of 15 in it, then
    it returns it as:

    #2/15/2005#

    btw: I am doing all these tests in the quick watch.

    Any ideas?

    >-----Original Message-----
    >Just a guess but maybe some of the dates have times in

    them so they aren't
    >equal to exactly 15/02/2005
    >
    >why not try > 15/02/2005 and < 16/02/2005 or

    something...
    >
    >Karl
    >
    >--
    >MY ASP.Net tutorials
    >http://www.openmymind.net/ - New and Improved (yes, the

    popup is
    >annoying)
    >http://www.openmymind.net/faq.aspx - unofficial newsgroup

    FAQ (more to
    >come!)
    >"VK" <> wrote in

    message
    >news:1f0601c5556b$d9c38be0$...
    >> Hello,
    >>
    >> I have a dataset which has one datatable in it. The dt
    >> has over 3000 rows in it. Now I would like to get the

    rows
    >> where the StartDate is 15 Feb 2005, so I did the

    following:
    >>
    >> ds.Tables(0).Select("StartDate = '15/02/2005'")
    >>
    >> However this returns me only 3 rows. I have tried other
    >> possiblities like:
    >>
    >> ds.Tables(0).Select("StartDate = '15 Feb 2005'")
    >> ds.Tables(0).Select("StartDate = #15/02/2005#")
    >> ds.Tables(0).Select("StartDate = '15/2/2005'")
    >>
    >> But all of them returns only 3 rows. I know that there

    are
    >> more then 3 rows for that date. I cheked the data from

    the
    >> dbase and compared the rows with the dt and found the
    >> dates, but I am not getting the expected result when I

    use
    >> Select.
    >>
    >> Can somebody help me please?
    >>
    >> Thanks

    >
    >
    >.
    >
     
    VK, May 10, 2005
    #3
  4. VK

    Karl Seguin Guest

    VK:
    The following code works for me:

    DataTable dt = new DataTable();
    dt.Columns.Add("Id", Type.GetType("System.Int32"));
    dt.Columns.Add("Date", Type.GetType("System.DateTime"));
    DataRow dr = null;

    dr = dt.NewRow();
    dr[0] = 1;
    dr[1] = DateTime.Now;
    dt.Rows.Add(dr);

    dr = dt.NewRow();
    dr[0] = 2;
    dr[1] = DateTime.Now.AddHours(1);
    dt.Rows.Add(dr);

    dr = dt.NewRow();
    dr[0] = 3;
    dr[1] = DateTime.Now.AddMinutes(121) ;
    dt.Rows.Add(dr);

    dr = dt.NewRow();
    dr[0] = 5;
    dr[1] = DateTime.Now.AddHours(4).AddMinutes(34);
    dt.Rows.Add(dr);

    dr = dt.NewRow();
    dr[0] = 6;
    dr[1] = DateTime.Now.AddDays(1);
    dt.Rows.Add(dr);

    dr = dt.NewRow();
    dr[0] = 7;
    dr[1] = DateTime.Now.AddDays(5);
    dt.Rows.Add(dr);


    DataRow[] rows = dt.Select("Date > #10/05/2005# AND Date < #11/05/2005#");


    Rows has the expected length of 4..The problem could certainly be your date
    format. It needs to be entered in the correct culture format...you can see
    this by just looking at what dateTime.Now looks like in your watch....aside
    from that, I'm thinking maybe your data isn't what you expect?

    Karl

    --
    MY ASP.Net tutorials
    http://www.openmymind.net/ - New and Improved (yes, the popup is
    annoying)
    http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
    come!)
    "VK" <> wrote in message
    news:1f4301c55572$db0ecc60$...
    > Thanks for the reply
    >
    > I tried:
    >
    > ds.tables(0).Select("StartDate > #15/02/2005# and
    > StartDate < #16/02/2005#")
    >
    > which returned:
    >
    > Run-time exception thrown : System.FormatException -
    > String was not recognized as a valid DateTime.
    >
    > I tried:
    >
    > ds.tables(0).Select("StartDate > #2/15/2005# and StartDate
    > < #2/16/2005#")
    >
    > which returned 0 rows
    >
    > Also tried:
    >
    > ds.tables(0).Select("StartDate > '15/02/2005' and
    > StartDate < '16/02/2005'")
    >
    > which returns also 0 rows.
    >
    > When I check a row, which has the date of 15 in it, then
    > it returns it as:
    >
    > #2/15/2005#
    >
    > btw: I am doing all these tests in the quick watch.
    >
    > Any ideas?
    >
    >>-----Original Message-----
    >>Just a guess but maybe some of the dates have times in

    > them so they aren't
    >>equal to exactly 15/02/2005
    >>
    >>why not try > 15/02/2005 and < 16/02/2005 or

    > something...
    >>
    >>Karl
    >>
    >>--
    >>MY ASP.Net tutorials
    >>http://www.openmymind.net/ - New and Improved (yes, the

    > popup is
    >>annoying)
    >>http://www.openmymind.net/faq.aspx - unofficial newsgroup

    > FAQ (more to
    >>come!)
    >>"VK" <> wrote in

    > message
    >>news:1f0601c5556b$d9c38be0$...
    >>> Hello,
    >>>
    >>> I have a dataset which has one datatable in it. The dt
    >>> has over 3000 rows in it. Now I would like to get the

    > rows
    >>> where the StartDate is 15 Feb 2005, so I did the

    > following:
    >>>
    >>> ds.Tables(0).Select("StartDate = '15/02/2005'")
    >>>
    >>> However this returns me only 3 rows. I have tried other
    >>> possiblities like:
    >>>
    >>> ds.Tables(0).Select("StartDate = '15 Feb 2005'")
    >>> ds.Tables(0).Select("StartDate = #15/02/2005#")
    >>> ds.Tables(0).Select("StartDate = '15/2/2005'")
    >>>
    >>> But all of them returns only 3 rows. I know that there

    > are
    >>> more then 3 rows for that date. I cheked the data from

    > the
    >>> dbase and compared the rows with the dt and found the
    >>> dates, but I am not getting the expected result when I

    > use
    >>> Select.
    >>>
    >>> Can somebody help me please?
    >>>
    >>> Thanks

    >>
    >>
    >>.
    >>
     
    Karl Seguin, May 10, 2005
    #4
  5. > Run-time exception thrown : System.FormatException -
    > String was not recognized as a valid DateTime.


    I had this Error days ago, the problem is the Culture if you have
    Formated your date to us standard and your webserver is de or other
    language you have an problem.

    You have to set the ds.Locale = new System.Globalization.CultureInfo(xx)

    Then your dates have the same Format.

    Greez The Filzmeister


    VK schrieb:
    > Thanks for the reply
    >
    > I tried:
    >
    > ds.tables(0).Select("StartDate > #15/02/2005# and
    > StartDate < #16/02/2005#")
    >
    > which returned:
    >
    > Run-time exception thrown : System.FormatException -
    > String was not recognized as a valid DateTime.
    >
    > I tried:
    >
    > ds.tables(0).Select("StartDate > #2/15/2005# and StartDate
    > < #2/16/2005#")
    >
    > which returned 0 rows
    >
    > Also tried:
    >
    > ds.tables(0).Select("StartDate > '15/02/2005' and
    > StartDate < '16/02/2005'")
    >
    > which returns also 0 rows.
    >
    > When I check a row, which has the date of 15 in it, then
    > it returns it as:
    >
    > #2/15/2005#
    >
    > btw: I am doing all these tests in the quick watch.
    >
    > Any ideas?
    >
    >
    >>-----Original Message-----
    >>Just a guess but maybe some of the dates have times in

    >
    > them so they aren't
    >
    >>equal to exactly 15/02/2005
    >>
    >>why not try > 15/02/2005 and < 16/02/2005 or

    >
    > something...
    >
    >>Karl
    >>
    >>--
    >>MY ASP.Net tutorials
    >>http://www.openmymind.net/ - New and Improved (yes, the

    >
    > popup is
    >
    >>annoying)
    >>http://www.openmymind.net/faq.aspx - unofficial newsgroup

    >
    > FAQ (more to
    >
    >>come!)
    >>"VK" <> wrote in

    >
    > message
    >
    >>news:1f0601c5556b$d9c38be0$...
    >>
    >>>Hello,
    >>>
    >>> I have a dataset which has one datatable in it. The dt
    >>>has over 3000 rows in it. Now I would like to get the

    >
    > rows
    >
    >>>where the StartDate is 15 Feb 2005, so I did the

    >
    > following:
    >
    >>>ds.Tables(0).Select("StartDate = '15/02/2005'")
    >>>
    >>>However this returns me only 3 rows. I have tried other
    >>>possiblities like:
    >>>
    >>>ds.Tables(0).Select("StartDate = '15 Feb 2005'")
    >>>ds.Tables(0).Select("StartDate = #15/02/2005#")
    >>>ds.Tables(0).Select("StartDate = '15/2/2005'")
    >>>
    >>>But all of them returns only 3 rows. I know that there

    >
    > are
    >
    >>>more then 3 rows for that date. I cheked the data from

    >
    > the
    >
    >>>dbase and compared the rows with the dt and found the
    >>>dates, but I am not getting the expected result when I

    >
    > use
    >
    >>>Select.
    >>>
    >>>Can somebody help me please?
    >>>
    >>>Thanks

    >>
    >>
    >>.
    >>
     
    Christian Filzwieser, May 12, 2005
    #5
  6. VK

    parhom_ua

    Joined:
    Oct 31, 2007
    Messages:
    1
    Column type

    It seems to me that your column that consists datetime does not have the dateTime type and so query that you pass in select() method compare dates as strings... :-D
     
    parhom_ua, Oct 31, 2007
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. J. Babe
    Replies:
    1
    Views:
    8,411
    Kevin Spencer
    Aug 15, 2003
  2. Fredrik Rodin

    Sort a datatable and create a new datatable

    Fredrik Rodin, Feb 16, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    9,100
    paul.mariotti
    Sep 28, 2007
  3. =?Utf-8?B?Qmx1ZWZsb3dlcg==?=

    Casting DataTable to class inherit from DataTable

    =?Utf-8?B?Qmx1ZWZsb3dlcg==?=, Apr 2, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    1,022
    =?Utf-8?B?Qmx1ZWZsb3dlcg==?=
    Apr 2, 2004
  4. jg
    Replies:
    1
    Views:
    752
    =?Utf-8?B?U2hhaWxlc2ggSmFubnU=?=
    Aug 17, 2004
  5. Ersin Gençtürk
    Replies:
    1
    Views:
    3,541
    Ersin Gençtürk
    Oct 6, 2004
Loading...

Share This Page