none
Need to query a dataset and get a List<> object RRS feed

  • Question

  • I know I'm close with this, here's what I have so far.  The List object is a FolderListDO

    Here's what I have:

    var f = from fl in (DataTable)ds.Tables["Folders"].AsEnumerable()
            where fl.Field("ParentID") == 1
            select new FolderListDO
    {
        ID = (int)fl.???
    }

    ID is a propery in the FolderListDO object, but I'm not sure how I get from fl to the specific field I want.  Any help is appreciated.
    Wednesday, April 15, 2009 10:19 PM

Answers

  • Actually, you almost had it right:

    Int32 parentID = ds.Tables["Folder"].AsEnumerable()
           .Where(f => f.Field<Int32>("ParentID") == 1)
           .Select(f => f.Field<Int32>("ColumnName"))
           .FirstOrDefault();

    Just supply the bold with what you want returned.
          
    John Grove - TFD Group, Senior Software Engineer, EI Division, http://www.tfdg.com
    • Marked as answer by Jhorra Thursday, April 16, 2009 5:26 PM
    Wednesday, April 15, 2009 10:56 PM

All replies

  • Actually, you almost had it right:

    Int32 parentID = ds.Tables["Folder"].AsEnumerable()
           .Where(f => f.Field<Int32>("ParentID") == 1)
           .Select(f => f.Field<Int32>("ColumnName"))
           .FirstOrDefault();

    Just supply the bold with what you want returned.
          
    John Grove - TFD Group, Senior Software Engineer, EI Division, http://www.tfdg.com
    • Marked as answer by Jhorra Thursday, April 16, 2009 5:26 PM
    Wednesday, April 15, 2009 10:56 PM
  • Note, you are querying a disconnected DataTable.

    "ID is a propery in the FolderListDO object............ "  <-- Note sure what you are attempting to do here.

    John Grove - TFD Group, Senior Software Engineer, EI Division, http://www.tfdg.com
    Thursday, April 16, 2009 1:38 PM