TestDataContext TDC = new TestDataContext();
protected void Page_Load(object sender, EventArgs e)
{
var query = from table in TDC.PTables
where table.salary >= 10000
orderby table.Age descending
select new
{
Name = table.Name.ToUpper(),
Age = table.Age,
Country = table.Country
};
gv1.DataSource = query;
gv1.DataBind();
//Showing a List of Process by LINQ
var process = from p in System.Diagnostics.Process.GetProcesses()
orderby p.ProcessName
select new
{
p.ProcessName,
p.Id,
p.Threads,
p.HandleCount,
p.WorkingSet64
};
foreach (var test in process)
{
Response.Write(test+"
");
");
}
//Showing a List of Files by LINQ
System.IO.DirectoryInfo DI = new System.IO.DirectoryInfo("D:\\USBBackUP\\Cards\\Cards");
var directoryList =
from f in DI.GetFiles("*.*",
System.IO.SearchOption.AllDirectories)
select f;
foreach( var row in directoryList)
{
Response.Write(row +"
");
");
}
}
protected void btnInsert_Click(object sender, EventArgs e)
{
PTable ptable = new PTable();
ptable.Age = "35";
ptable.Name = "Nitin Sharma";
ptable.Country = "INDIA";
TDC.PTables.InsertOnSubmit(ptable);
TDC.SubmitChanges();
gv1.DataBind();
}
protected void btnDelete_Click(object sender, EventArgs e)
{
try
{
PTable todelete = TDC.PTables.Single(p => p.Name.Contains("Nitin"));
TDC.PTables.DeleteOnSubmit(todelete);
TDC.SubmitChanges();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
gv1.DataBind();
}
protected void btnUpdate_Click(object sender, EventArgs e)
{
var update = (from table in TDC.PTables
where table.CountryID == 8
select table).Single();
update.Name = txtName.Text;
TDC.SubmitChanges();
gv1.DataBind();
txtName.Text = "";
}
Thanks,
Nitin Sharma