Language Integrated Query (LINQ)
is a Microsoft .NET Framework component that adds native data querying
capabilities to .NET languages.
Language-Integrated Query (LINQ) is a set of features introduced in
Visual Studio 2008 that extends powerful query capabilities to the language syntax
of C# and Visual Basic. LINQ introduces standard, easily-learned patterns for
querying and updating data, and the technology can be extended to support
potentially any kind of data store. Visual Studio includes
LINQ provider assemblies that enable the use of LINQ with .NET Framework
collections, SQL Server databases, ADO.NET Datasets, and XML documents.
LINQ has three
major components:
1. LINQ to Objects
2. LINQ to ADO.NET, 3 sub parts
- LINQ to Dataset (originally called LINQ over Dataset)
- LINQ to Entities
- LINQ to SQL (originally called DLinq)
3. LINQ to XML (originally called XLinq)
LINQ to Objects deals with in-memory data. Any class that implements the
IEnumerable<T> interface (in the System.Collections.Generic namespace)
can be queried with SQO.
LINQ to ADO.NET deals with data from external sources, basically anything
ADO.NET can connect to. Any class that implements IEnumerable<T> or
IQueryable<T> (in the System.Query namespace) can be queried with SQO.
LINQ to XML is a comprehensive API for in-memory XML programming. Like
the rest of LINQ, it includes SQO, and it can also be used in concert with LINQ
to ADO.NET, but its primary purpose is to unify and simplify the kinds of
things that disparate XML tools, like XQuery, XPath, and XSLT, are typically
used to do. In this chapter we’ll preview LINQ to SQL and LINQ to DataSet,
since they’re most closely related to the C# database programming we’ve covered
in this book.
1 Fill Data in Gridview:
public
void showGridData()
{ LinqDataContext dataContaxt = new LinqDataContext (); var q =from a in dataContaxt.GetTable<emp>() select a; GridView1.DataSource = q; GridView1.DataBind(); } |
2 Search record:
public
void SearchQuery()
{ LinqDataContext dataContaxt = new LinqDataContext (); var q = from a in dataContaxt.GetTable< emp >() where a.name == TextBox3.Text select a; GridView1.DataSource = q; GridView1.DataBind(); } |
3 Insert Record:
public
void InsertQuery()
{ LinqDataContext dataContaxt = new LinqDataContext (); emp objEmp = new emp (); objEmp.name = TextBox3.Text; objEmp.passw = TextBox5.Text; objEmp.fname = TextBox4.Text; dataContaxt.bios.InsertOnSubmit(objEmp); dataContaxt.SubmitChanges(); showgridview(); } |
4 Update record:
public
void UpdateQuery()
{ LinqDataContext dataContaxt = new LinqDataContext (); emp objEmp = dataContaxt.emps.Single(emp => emp.name == TextBox3.Text); objEmp.passw = TextBox5.Text; objEmp.fname = TextBox4.Text; objEmp.SubmitChanges(); } |
5 Delete Record:
public
void DeleteQuery()
{ LinqDataContext dataContaxt = new LinqDataContext (); emp objEmp = dataContaxt.bios.Single(emp => emp.name == TextBox3.Text); dataContaxt.emps.DeleteOnSubmit(objEmp); dataContaxt.SubmitChanges(); } |
No comments:
Post a Comment