Escolar Documentos
Profissional Documentos
Cultura Documentos
Science
PRACTICAL NO. 7- Programs using LINQ
1) AIM: Create an array of names (string) and an array of integers separately and perform the following
LINQ queries on them. Further display the query result in a label.
a. Display all the names from the string array.
b. Display all the names from string array which contain l.
c. Display all the numbers from integer array.
d. Display all the numbers incremented by 1 from integer array.
e. Display all the names from names array in upper case and lowercase simultaneously.
CODE:
using System;
using
System.Collections.Generic;
using System.Linq;
using System.Web;
using
System.Web.UI;
using System.Web.UI.WebControls;
2) AIM: Create a XML file with three properties CustNo. And CustName, Salary. Create an application to write
LINQ query to fetch XML file data and display it in gridview.
3) AIM: Create a class called Customer with two properties CustNo and CustName. Create an application to write
LINQ query to fetch CustName whose CustNo is greater than 5.
CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Linq;
using System.Collections;
public partial class _Default : System.Web.UI.Page
{
public class Customer
{
public int cid;
public string cname;
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
ArrayList list = new ArrayList();
Customer c1 = new Customer(); c1.cid
= 5;
c1.cname = "Sam";
Customer c2 = new Customer();
c2.cid = 6;
c2.cname = "John";
Customer c3 = new Customer();
c3.cid = 7;
c3.cname = "Tom";
Customer c4 = new Customer();
c4.cid = 8;
c4.cname = "Sara";
list.Add(c1);
list.Add(c2);
list.Add(c3);
list.Add(c4);
var f = from Customer i in list
where i.cid > 5
select i;
foreach (var d in f)
OUTPUT SCREEN:
4)
AIM: Write a LINQ Application that displays the data on PageLoad Event and also show how JOINS are used.
CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using
System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Linq;
using System.Collections;
public partial class _Default : System.Web.UI.Page
{
class Customer
{
public int ID ;
public string Name ;
}
class Order
{
public int ID ;
public string Product ;
}
protected void Page_Load(object sender, EventArgs e)
{
var customers = new Customer[]
{
new Customer{ID = 5, Name = "Sam"},
new Customer{ID = 6, Name = "Dave"},
5)