DataTable.Select Method

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

    #1

    DataTable.Select Method

    Hi,

    Can the DataTable.Selec t Method use 'Distinct' to remove duplicate rows? If
    so how? I tried, however code triggered error 'no colmn 'Distinct' found'.

    Thanks
    Harry




  • Anushi

    #2
    Re: DataTable.Selec t Method

    Hi Harry,

    I don't believe distinct is supported. The only reserved words used in the
    expression parser are:
    And, Or, True, False, Is, In, Like, Not, Null, Between, Child, and Parent.
    You'll have to code it by hand.
    Here you go....

    [HOW TO: Implement a DataSet SELECT DISTINCT Helper Class in Visual Basic
    ..NET]


    HTH,
    Anushi (Grapecity)



    "harry" <harry@nospam > wrote in message
    news:eEqxMexmEH A.2588@TK2MSFTN GP12.phx.gbl...[color=blue]
    > Hi,
    >
    > Can the DataTable.Selec t Method use 'Distinct' to remove duplicate rows?[/color]
    If[color=blue]
    > so how? I tried, however code triggered error 'no colmn 'Distinct' found'.
    >
    > Thanks
    > Harry
    >
    >
    >
    >[/color]


    Comment

    • One Handed Man \( OHM - Terry Burns \)

      #3
      Re: DataTable.Selec t Method

      No this is not possible using the Select method of the dataTable. You will
      have to build in your functionality or ammend your query to return distinct
      rows from the SQL server which is probable more sensible.

      --

      OHM ( Terry Burns )
      . . . One-Handed-Man . . .
      If U Need My Email ,Ask Me

      Time flies when you don't know what you're doing

      "harry" <harry@nospam > wrote in message
      news:eEqxMexmEH A.2588@TK2MSFTN GP12.phx.gbl...[color=blue]
      > Hi,
      >
      > Can the DataTable.Selec t Method use 'Distinct' to remove duplicate rows?[/color]
      If[color=blue]
      > so how? I tried, however code triggered error 'no colmn 'Distinct' found'.
      >
      > Thanks
      > Harry
      >
      >
      >
      >[/color]


      Comment

      • Cor Ligthert

        #4
        Re: DataTable.Selec t Method

        Harry,

        As Anushi wrote there is no standard distinct in Net 1.0 or 1.1

        There is a sample in a page on MSDN, I find this sample I once made more
        easy (and it is more complete)

        \\\
        Me.DataGrid1.Da taSource = distinct(dt, "MyDistinctElem ent")
        End Sub
        Public Function distinct(ByVal dt As DataTable, _
        ByVal dist As String) As DataTable
        Dim dtclone As DataTable = dt.Clone
        Dim dv As New DataView(dt)
        dv.Sort = dist
        Dim myselold As String = ""
        For i As Integer = 0 To dv.Count - 1
        If myselold <> dv(i)(dist).ToS tring Then
        Dim drn As DataRow = dtclone.NewRow
        For y As Integer = 0 To drn.ItemArray.L ength - 1
        drn(y) = dv(i)(y)
        Next
        myselold = dv(i)(dist).ToS tring
        dtclone.Rows.Ad d(drn)
        End If
        Next
        Return dtclone
        End Function
        ///
        I hope this helps?

        Cor[color=blue]
        >
        > Can the DataTable.Selec t Method use 'Distinct' to remove duplicate rows?[/color]
        If[color=blue]
        > so how? I tried, however code triggered error 'no colmn 'Distinct' found'.
        >
        > Thanks
        > Harry
        >
        >
        >
        >[/color]


        Comment

        • harry

          #5
          Re: DataTable.Selec t Method


          Thanks everyone for your help.

          Regards
          Harry


          "harry" <harry@nospam > wrote in message
          news:eEqxMexmEH A.2588@TK2MSFTN GP12.phx.gbl...[color=blue]
          > Hi,
          >
          > Can the DataTable.Selec t Method use 'Distinct' to remove duplicate rows?
          > If so how? I tried, however code triggered error 'no colmn 'Distinct'
          > found'.
          >
          > Thanks
          > Harry
          >
          >
          >
          >[/color]


          Comment

          • One Handed Man \( OHM - Terry Burns \)

            #6
            Re: DataTable.Selec t Method

            AFAIK, I think the answer is no. This has four overloaded functions none of
            which allow this, the filter is just that and has now way of knowing if it
            has already displayed a row.


            --

            OHM ( Terry Burns )
            . . . One-Handed-Man . . .
            If U Need My Email ,Ask Me

            Time flies when you don't know what you're doing

            "harry" <harry@nospam > wrote in message
            news:eEqxMexmEH A.2588@TK2MSFTN GP12.phx.gbl...[color=blue]
            > Hi,
            >
            > Can the DataTable.Selec t Method use 'Distinct' to remove duplicate rows?[/color]
            If[color=blue]
            > so how? I tried, however code triggered error 'no colmn 'Distinct' found'.
            >
            > Thanks
            > Harry
            >
            >
            >
            >[/color]


            Comment

            Working...