Mar 08
26
LINQ to DataSet
- Perform set operations on sequences of DataRow objects.
- Retrieve and set DataColumn values
- Obtain a LINQ standard IEnumerable sequence from a DataTable so Standard Query Operatorsmay be called.
To use LINQ to Dataset include next namespaces
-
using System.Data; using System.Linq;
Step by Step Exemple:
Starting with a simple class:
-
class Student {
-
public int Id;
-
public string Name;
-
}
this class is like a table where we have an row Id (public int Id) and a value (here is Name public string Name)
Next convert a list of Student Class in a Data Table
-
// create DataTable
-
// fill with info
-
foreach (Student student in students){
-
table.Rows.Add(student.Id, student.Name);
-
}
Other Query examples:
There are to way of write a LINQ Query
Query expression
and
Method Query
-
// Query expression example
-
var query = from r in customerDataTable.AsEnumerable()
-
where r.Field("LastName") == "Smith"
-
select r.Field(“FirstName”);
-
// same example in Method query
-
var query = customerDataTable.AsEnumerable()
-
.Where(dr => dr.Field("LastName") == "Smith")
-
.Select(dr => dr.Field("FirstName"));
Buy Visual studio:
- Microsoft Visual Studio 2008 Professional
632$
- Microsoft Visual Studio 2008 Standard
240$
- Microsoft Visual Studio 2008 Professional Upgrade
452$
- Microsoft Visual Studio 2008 Standard Upgrade
165$
- Microsoft Visual Studio 2008 Professional with MSDN Premium
2225$