problem with DataTable.Select

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jeff

    #1

    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.Selec t("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.Selec t("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?




  • DeveloperX

    #2
    Re: problem with DataTable.Selec t

    On 28 Jan, 12:55, "Jeff" <do...@spam.mew rote:
    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.Selec t("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.Selec t("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("A Date", Type.GetType("S ystem.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.WriteLi ne(rows.Length. ToString()); //returns 1
    rows = data.Tables[0].Select("ADate '01/11/2007'");
    Console.WriteLi ne(rows.Length. ToString()); //returns 1


    but


    DataSet data = new DataSet();
    data.Tables.Add (new DataTable());
    data.Tables[0].Columns.Add("A Date", Type.GetType("S ystem.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.WriteLi ne(rows.Length. ToString()); //returns 0
    rows = data.Tables[0].Select("ADate '11/01/2007'");
    Console.WriteLi ne(rows.Length. ToString()); //returns 3


    gives the results you get. Your dates are being interpreted as MM/DD
    not DD/MM.


    Comment

    • Ignacio Machin \( .NET/ C# MVP \)

      #3
      Re: problem with DataTable.Selec t

      Hi,


      Most probably those are not valid dates , could you try it without the time
      component?

      --
      Ignacio Machin
      The #1 Warehouse Management System & Direct Store Delivery Software (DSD) for QuickBooks & ERP Systems – LaceUp Solutions

      Mobile & warehouse Solutions.
      "Jeff" <donot@spam.mew rote in message
      news:%23spfU0aY IHA.5980@TK2MSF TNGP04.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.Selec t("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.Selec t("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?
      >
      >
      >
      >

      Comment

      • Nicholas Paldino [.NET/C# MVP]

        #4
        Re: problem with DataTable.Selec t

        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]
        - mvp@spam.guard. caspershouse.co m

        "Jeff" <donot@spam.mew rote in message
        news:%23spfU0aY IHA.5980@TK2MSF TNGP04.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.Selec t("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.Selec t("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?
        >
        >
        >
        >

        Comment

        Working...