Blue Theme Orange Theme Green Theme Red Theme
 
6 Months Free & No Setup Fees ASP.NET 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 filter data

 by Abhijit barua on Jan 21, 2012

select query on datatable for filter data
Comments: 0 Views: 450 Printable Version 

I go through lots of site for select query on datatable. But  most of the time I not get 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 datatble 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:
 
Comments not available.
6 Months Free & No Setup Fees ASP.NET 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 ... 
6 Months Free & No Setup Fees ASP.NET Hosting!
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.