Source Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication9
{
class Program
{
static void Main(string[] args)
{
StudentDemoDataContext context = new StudentDemoDataContext();
#region Reterive
//Reteriving all the Records
foreach (var r in context.Students)
{
Console.WriteLine(r.Name + r.Subject);
}
#endregion
#region Insert
Student std = new Student
{
RollNumber = "8",
Name = "Mahesh",
Subject = "C#"
};
context.Students.InsertOnSubmit(std);
context.SubmitChanges();
#endregion
#region Update
Student std = (from r in context.Students
where r.RollNumber == "1"
select r).First();
std.Name = "Scott";
std.Subject = "ASP.Net MVC";
context.SubmitChanges();
#endregion
#region Delete
StudentDemoDataContext context1 = new StudentDemoDataContext();
Student std = new Student
{
RollNumber = "8",
Name = "Mahesh",
Subject = "C#"
};
context.Students.Attach(std);
context.Students.DeleteOnSubmit(std);
context.SubmitChanges();
#endregion
Console.Read();
}
}
}
Leave a Reply