Dharmendra (.Net)

Thursday, 2 July 2015

Convert DataTable to Generic List in C#

List<Cards> target = dt.AsEnumerable()
    .Select(row => new Cards
    {
        // assuming column 0's type is Nullable<long>
        CardID = row.Field<long?>(0).GetValueOrDefault(),
        CardName = String.IsNullOrEmpty(row.Field<string>(1))
            ? "not found"
            : row.Field<string>(1),
    }).ToList();
Posted by Unknown at 00:26
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest

No comments:

Post a Comment

Newer Post Older Post Home
Subscribe to: Post Comments (Atom)

Blog Archive

  • ►  2016 (8)
    • ►  July (1)
    • ►  June (1)
    • ►  May (3)
    • ►  February (3)
  • ▼  2015 (46)
    • ►  September (2)
    • ►  August (2)
    • ▼  July (9)
      • C# program that creates 2D array
      • Difference between InvariantCulture and Ordinal st...
      • Find StartDate and EndDate using while loop in sql...
      • Days difference between two dates duplicate
      • Convert varchar dd/mm/yyyy to dd/mm/yyyy datetime
      • Convert Time DataType into AM PM Format:
      • How to insert a data table into SQL Server databas...
      • Getting name of Page being requested/was requested
      • Convert DataTable to Generic List in C#
    • ►  June (1)
    • ►  May (6)
    • ►  April (9)
    • ►  March (7)
    • ►  February (1)
    • ►  January (9)
  • ►  2014 (51)
    • ►  December (6)
    • ►  November (7)
    • ►  September (2)
    • ►  August (6)
    • ►  July (5)
    • ►  June (5)
    • ►  May (4)
    • ►  April (14)
    • ►  March (2)
  • ►  2013 (1)
    • ►  February (1)

About Me

Unknown
View my complete profile
Watermark theme. Powered by Blogger.