none
LINQ with DataTable RRS feed

  • Question

  • I am using LINQ on datatable and select distinct Column from data table
    but when i use following code then i got incomplete string in str. i think its due to ASEnumerable().
    if a character is repeating in value then its skipped!
    i dont understand, why its happened?
    Can any one tell me how can i select distinct data values from a data table using LINQ?
      var query = (from rec in this.Objects.Tables[0].AsEnumerable()
                   select rec.Field<String>("TblName").Distinct().ToList());
    
                    foreach (var row in query)
                  {
                      String str = new String(row.ToArray());
                  }


    Zubair Khalid
    Wednesday, November 18, 2009 10:10 AM

Answers

  • > if a character is repeating in value then its skipped!

    That's what Distinct() does (skips duplicates).  Take it out if you do not want that behavior.

    If you have additional questions, post an example that shows the input data and output you expect.
    • Marked as answer by Zubair Khalid Thursday, November 19, 2009 7:00 AM
    Wednesday, November 18, 2009 11:57 PM

All replies

  • > if a character is repeating in value then its skipped!

    That's what Distinct() does (skips duplicates).  Take it out if you do not want that behavior.

    If you have additional questions, post an example that shows the input data and output you expect.
    • Marked as answer by Zubair Khalid Thursday, November 19, 2009 7:00 AM
    Wednesday, November 18, 2009 11:57 PM
  • Its now working with following script

     var query = (from rec in this.Objects.Tables[0].AsEnumerable()
    select rec.Field<String>("TblName").ToList()).Distinct();

    Thanks for guiding me.

    Zubair Khalid
    Thursday, November 19, 2009 7:00 AM