DataTable.Select() is bugged?

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

    #1

    DataTable.Select() 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




  • ronchese

    #2
    Re: DataTable.Selec t() is bugged?

    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:euMiQj8cGH A.536@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




    Comment

    • Jay B. Harlow [MVP - Outlook]

      #3
      Re: DataTable.Selec t() is bugged?

      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:euMiQj8cGH A.536@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





      Comment

      • ronchese

        #4
        Re: DataTable.Selec t() is bugged?

        I tryied # also, like showed in PS area, at end of e-mail :D
        [color=blue]
        > 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 #[/color]

        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]" <Jay_Harlow_MVP @tsbradley.net> wrote in message news:%23CU7Qs8c GHA.2188@TK2MSF TNGP05.phx.gbl. ..[color=blue]
        > 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:euMiQj8cGH A.536@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
        >
        >
        >
        >
        >[/color]

        Comment

        • ronchese

          #5
          Re: DataTable.Selec t() is bugged?

          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:u9kUks8cGH A.2456@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:euMiQj8cGH A.536@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




          Comment

          • ronchese

            #6
            And another yet tip

            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:OgOB138cGH A.4932@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:u9kUks8cGH A.2456@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:euMiQj8cGH A.536@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




            Comment

            • Cor Ligthert [MVP]

              #7
              Re: DataTable.Selec t() is bugged?

              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:euMiQj8cGH A.536@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




              Comment

              Working...