![]() |
Platforms, Frameworks & Libraries »
Mobile Development »
General
Advanced
Usage of LINQ and Datasets in Compact Framework 3.5By Oleg LevinIntroduction to working with LINQ and Datasets in Compact Framework 3.5 Beta 1 |
C# 3.0, Windows, Win Mobile, .NET CF, .NET, Mobile, Visual Studio, LINQ, Dev
|
|
Advanced Search |
|
|
|
||||||||||||||||

In this article, I will speak about LINQ and Compact Framework 3.5. I've written a simple example to demonstrate how we can use LINQ and Dataset to manipulate data.
What is LINQ? LINQ is a codename for the set of extensions to the .NET Framework that encompass language-integrated data query, set, and transform operations. It includes extensions to the C# and Visual Basic languages with native language syntax for queries. It also provides class libraries to take advantage of these capabilities. With the release of Compact Framework 3.5 and Visual Studio "Orcas" Beta 1, LINQ extensions are now also available for mobile development.
In this example, I will demonstrate a simple application that has one form. It displays and searches countries' information in a grid. For an illustration of how to work with LINQ and Dataset, the application will retrieve data from the SQL Server Compact Edition file demo.sdf. The application uses Typed Data Adapter as the Data Access Layer and DataTable as the data type.

In the code below, I am retrieving data from a database and filling in the Countries DataTable. After that, just for illustration, I am using LINQ to sort and display the data in a grid through the bindingSource object.
///Loading data from demo.sdf to Countries table
private void LoadData()
{
///Get Data
Countries = dal.GetData();
///Building LINQ Query
var query = from r in Countries.AsEnumerable()
orderby r.Field<string>("Name") ascending
select new
{
Code = r.Field<string>("Code"), Name = r.Field<string>("Name")
};
///Binding data
bindingSource1.DataSource = query;
}
In the code below, I am using LINQ to search data in DataTable.
///Building LINQ Query
var query = from r in Countries.AsEnumerable()
where r.Field<string>("Name").ToLower().Contains(txtSearch.Text.ToLower())
orderby r.Field<string>("Name") ascending
select new
{
Code = r.Field<string>("Code"), Name = r.Field<string>("Name")
};
///Binding data
bindingSource1.DataSource = query;
As you can see, LINQ is very easy and intuitive to use. Its syntax is quite similar to that of SQL and it is a part of the C# and Visual Basic languages. We can use it to manipulate data in many scenarios.
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 14 Jun 2007 Editor: Sean Ewington |
Copyright 2007 by Oleg Levin Everything else Copyright © CodeProject, 1999-2009 Web10 | Advertise on the Code Project |