DataTable.Select distinct Method Query

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?dHZpbg==?=

    #1

    DataTable.Select distinct Method Query

    Hi everybody
    i have a datatable, i want to select distinct value from datatable and not
    database.
    so is there any method that can provide this query:
    Select DISTINCT from DataTable
    please help me
    thanks
    Tvin
  • Marc Gravell

    #2
    Re: DataTable.Selec t distinct Method Query

    Can you clarify the question? I'm not 100% sure I have followed it...

    However, looking forward a few weeks, LINQ supports this via
    Distinct() [which can accept a comparer], and .NET 3.5 ships with LINQ
    extensions for DataTable etc.

    I may not have fully followed the question, though.

    Marc


    Comment

    • =?Utf-8?B?dHZpbg==?=

      #3
      Re: DataTable.Selec t distinct Method Query

      Hi Marc thanks for your reply
      i fill datatable from database, after that i don't want to use the database
      again to select the same information but with different Query like: select
      distinct field ...

      so i want to know if there is select distinct method for datatable.

      thanks
      "Marc Gravell" wrote:
      Can you clarify the question? I'm not 100% sure I have followed it...
      >
      However, looking forward a few weeks, LINQ supports this via
      Distinct() [which can accept a comparer], and .NET 3.5 ships with LINQ
      extensions for DataTable etc.
      >
      I may not have fully followed the question, though.
      >
      Marc
      >
      >
      >

      Comment

      • Marc Gravell

        #4
        Re: DataTable.Selec t distinct Method Query

        With LINQ (.NET 3.5, C# 3), yes:

        var distinctNames = (
        from row in untypedDataTabl e.AsEnumerable( )
        select row.Field<strin g>("Name")).Dis tinct();

        foreach (var name in query) {
        Console.WriteLi ne(name);
        }

        alternatively, if typed:

        var distinctNames = (
        from row in typedDataTable
        select row.Name).Disti nct();

        Marc


        Comment

        • =?Utf-8?B?dHZpbg==?=

          #5
          Re: DataTable.Selec t distinct Method Query

          Hi Marc

          do you think i can use this LINQ idea with vb.net ?

          thanks

          Tvin

          "Marc Gravell" wrote:
          With LINQ (.NET 3.5, C# 3), yes:
          >
          var distinctNames = (
          from row in untypedDataTabl e.AsEnumerable( )
          select row.Field<strin g>("Name")).Dis tinct();
          >
          foreach (var name in query) {
          Console.WriteLi ne(name);
          }
          >
          alternatively, if typed:
          >
          var distinctNames = (
          from row in typedDataTable
          select row.Name).Disti nct();
          >
          Marc
          >
          >
          >

          Comment

          • Marc Gravell

            #6
            Re: DataTable.Selec t distinct Method Query

            I know that the answer is yes, but I don't know enough VB to prove
            it ;-p

            Either way, you'll need to wait a few weeks for .NET 3.5 to be
            released.

            Marc

            Comment

            Working...