Steveluo’s Blog

Just another WordPress.com weblog

Linq(2) to DataTable

Posted by steveluo on July 19, 2009

Generally we need get an  initial dataset  from Database by Sql   and then use  linq to filter it again to serve different purposes.   the article show how to create a tableView based on linq:

  • EnumerableRowCollection query   
  •               = from customer in dtCustomer.AsEnumerable()   
  •                 where customer.Field(“State”) == “NJ”  
  •                 select customer;   
  •             DataView njview = query.AsDataView();  

    the chapter Chapter 14 in LinQ in Action gives us the details.  and Other examples on the web and Linq to DataTable  example1 

  • Points to understand Linq:  (from Joseph Rattz’s book)
    1)  linq, a query,  returnes set of objects is called a sequence.  Most linq sequences are of type IEnumerable<T>
    2)  a lambda expression in C# with format:   
             a)
    (param1, param2, …paramN) => expr
             b) 
    (param1, param2, …paramN) =>   {   statement1; statement2; … statementN; return(lambda_expression_return_type); }
           e.g:   
    x => x.Length > 0   could be read as   “input x returns x.Length > 0.”

    Linq Wiki
    get data from Excel by linq

     

     

     

    Advertisements

    Leave a Reply

    Fill in your details below or click an icon to log in:

    WordPress.com Logo

    You are commenting using your WordPress.com account. Log Out / Change )

    Twitter picture

    You are commenting using your Twitter account. Log Out / Change )

    Facebook photo

    You are commenting using your Facebook account. Log Out / Change )

    Google+ photo

    You are commenting using your Google+ account. Log Out / Change )

    Connecting to %s

     
    %d bloggers like this: