Blue Theme Orange Theme Green Theme Red Theme
 
Team Foundation Server Hosting
Home | Forums | ASP.NET 2.0 Tutorials | Web Services | How Do I...? | Class Browser | WPF Quick Starts | Advertise with Us
 | Consulting  
Submit an Article Submit a Blog 
Search :       Advanced Search »
Home » Blogs Home » Blog Detail

Select Query on DataTable for filtering Data Using LINQ

 by Abhijit barua on Jan 21, 2012

I go through lots of site for select query on DataTable. But most of the time I did not get a suitable solution. So, at last I use LINQ to filter data from DataTable.
Comments: 1 Views: 1299 Printable Version 

I go through lots of site for select query on DataTable. But most of the time I did not get a suitable solution. So, at last I use linq to filter data from datatable. So I share my code below:-


DataTable dt = new DataTable();

 string sqlStatement1 = "select * from hsswith_view where cp_amount<='" + bug_amount + "' and no_of_days >='" + no_of_days + "'  or ep_amount<='" + bug_amount + "' and no_of_days >='" + no_of_days + "'";

 SqlCommand sqlCmd1 = new SqlCommand(sqlStatement1,connection);                                                                SqlDataAdapter sqlDa1 = new SqlDataAdapter(sqlCmd1);
          sqlDa1.Fill(dt1);

            var query = from r in dt1.AsEnumerable()
                        where r.Field<string>("pax") == no_person

                        select
new

                        {

                            entry_id = r["entry_id"].ToString(),

                            pax = r["pax"].ToString(),
                            package = r["package"].ToString(),
                            no_of_days = r["no_of_days"].ToString(),
                            cp_amount = r["cp_amount"].ToString(),
                           
                            ep_amount = r["ep_amount"].ToString()

                       };
 

            GridView1.DataSource = query;

            GridView1.DataBind();


First of all I select data using one select query and fill it at datatable(dt1). Now I write linq query to extract data from dt1 DataTable and bind the values at GridView. These much.

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
 
What do you say about this post? Post a comment here
*Title:
*Comment:
 

Thanks a lot for sharing this technique by Biswarup Saha On Jan 23, 2012
Great Job Mr.Barua. Keep Posting for us

Team Foundation Server Hosting
Become a Sponsor

 Blogger's Profile
Age: 30
Location:
Title: Developer
Joined: Nov 18, 2011
Education: Masters Degree
 More Blogs from this Blogger
No record available
 Latest Blogs
[Video] OnClose Handler
[Video] Storing and Loading the Window and Toolbar position
The Euclidean Algorithm
Swapping Exe Process
How Exe file is Generated by VS2005 C++ Project?
What is Exe
Header files: Multiple Inclusion problem - Solution B
Header files: Multiple Inclusion problem - Solution A
Header files: Multiple Inclusion problem - Reason
Header files: Multiple Inclusion problem
View all »
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 
Team Foundation Server Hosting
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.