Click here to Skip to main content
6,291,722 members and growing! (15,313 online)
Email Password   helpLost your password?
Platforms, Frameworks & Libraries » Mobile Development » General     Advanced

Usage of LINQ and Datasets in Compact Framework 3.5

By Oleg Levin

Introduction 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
Posted:14 Jun 2007
Views:31,175
Bookmarked:25 times
Announcements
Loading...
 
Search    
Advanced Search
printPrint   Broken Article?Report       add Share
  Discuss Discuss   Recommend Article Email
8 votes for this article.
Popularity: 4.11 Rating: 4.56 out of 5

1
1 vote, 12.5%
2

3

4
7 votes, 87.5%
5

Screenshot - demo.jpg

Introduction

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.

Background

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.

About the sample

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.

Screenshot - ds.jpg

LINQ in action

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;

Conclusion

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.

History

  • 14 June, 2007 -- Original version posted

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Oleg Levin


Member

Occupation: Software Developer
Company: SoftSolutions
Location: Israel Israel

Other popular Mobile Development articles:

  • Writing Your Own GPS Applications: Part 2
    In part two of the series, the author of "GPS.NET" teaches developers how to write GPS applications suitable for the real world by mastering GPS precision concepts. Source code includes a working NMEA interpreter and sample high-precision application in C# and VB.NET.
  • Writing Your Own GPS Applications: Part I
    What is it that GPS applications need to be good enough to use for in-car navigation? Also, how does the process of interpreting GPS data actually work? In this three-part series, I will cover both topics and give you the skills you need to write a commercial-grade GPS application.
  • Learn How to Find GPS Location on Any SmartPhone, and Then Make it Relevant
    A step by step tutorial for getting GPS from any SmartPhone, even without GPS built in, and then making location useful.
  • Pocket 1945 - A C# .NET CF Shooter
    An article on Pocket PC game development
  • iPhone UI in Windows Mobile
    It's an interface that works with transparency effects. As a sample I used an interface just like the iPhone one. In this tutorial I am explaining how simple is working with transparency on Windows Mobile.
Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 19 of 19 (Total in Forum: 19) (Refresh)FirstPrevNext
QuestionHow about the update dataRow in LINQ? Pinmemberagskid18:21 1 Jul '09  
AnswerRe: How about the update dataRow in LINQ? PinmemberOleg Levin19:13 1 Jul '09  
GeneralRe: How about the update dataRow in LINQ? Pinmemberagskid4:19 2 Jul '09  
AnswerRe: How about the update dataRow in LINQ? PinmemberOleg Levin5:41 2 Jul '09  
GeneralHi there PinmemberSebulba_se6:29 10 Sep '08  
GeneralRe: Hi there PinmemberOleg Levin8:00 10 Sep '08  
QuestionAsEnumerable() does not exist. Pinmemberzhenyulu200313:04 17 Aug '07  
AnswerRe: AsEnumerable() does not exist. PinmemberOleg Levin9:37 18 Aug '07  
GeneralRe: AsEnumerable() does not exist. Pinmemberzhenyulu20033:56 20 Aug '07  
GeneralCompact Framework PinmemberPamela198422:38 12 Jul '07  
GeneralRe: Compact Framework PinmemberOleg Levin3:56 13 Jul '07  
GeneralRe: Compact Framework PinmemberPamela19844:17 15 Jul '07  
GeneralRe: Compact Framework PinmemberOleg Levin9:32 15 Jul '07  
GeneralRe: Compact Framework [modified] PinmemberPamela198420:43 17 Jul '07  
QuestionLINQ Pinmembergagliapas14:43 19 Jun '07  
AnswerRe: LINQ PinmemberOleg Levin21:02 19 Jun '07  
Generalnice PinmemberSacha Barber23:37 14 Jun '07  
GeneralRe: nice PinmemberOleg Levin7:14 15 Jun '07  
GeneralThanks Pinmembermerlin9816:21 14 Jun '07  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin 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