C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




How to filter the datatable


Posted Date: 27 Feb 2007    Resource Type: Code Snippets    Category: ADO.NET

Posted By: kumar       Member Level: Diamond
Rating:     Points: 10



We Often use to come across the situation where we use to filter the data with some condition, here i have taken a products table from northwind database and now i want to show all the products name which come under cateogory 1(Beverages)

								
SqlConnection myConn = new SqlConnection(strConString);
string strSql = "select * from Products";

DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(strSql, myConn);
da.Fill(ds);

DataTable dt = ds.Tables[0];

// The following line filters the data by "CategoryId = 1" and returns an array of DataRow
DataRow[] dRow = dt.Select("CategoryId=1");

for (int i = 0; i < dRow.Length; i++)
{
Response.Write("
Row " + dRow[i]["ProductName"].ToString());
}




Responses

Author: Kapil Dhawan    17 Jun 2008Member Level: Gold   Points : 2
Hello
Nice piece of code
Thanks for sharing your knowledge with us.
I hope to see more good code from your side
This code will help lots of guys
Thanks to you
Regards,
Kapil



Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Remove duplicate records from a table
Previous Resource: Data Relation between Two Different Datasets
Return to Discussion Resource Index
Post New Resource
Category: ADO.NET


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

email fax service

Contact Us    Privacy Policy    Terms Of Use