Subhash Sharma

Subhash Sharma
Subhash Sharma

This is Subhash Sharma(Software Engineer) Blog

Welcome to this blog and find every solution.............

Search This Blog

Software Engineer(Subhash Sharma)

Software Engineer(Subhash Sharma)
Software Engineer
Showing posts with label Add Update through Linq. Show all posts
Showing posts with label Add Update through Linq. Show all posts

Tuesday, December 21, 2010

Add Update through Linq

Create one .dbml file and make DataBase connection there and drag and drop the table inside the Dbml window. and right clcik on the field which field u want primary key and select the property option and give there True as primary key.

protected void btnUpdate_Click(object sender, EventArgs e)
{
linqStudent linObj = new linqStudent();
var obj = linObj.Students.SingleOrDefault(o => o.Roll == txtRoll.Text);
if (obj != null)
{
obj.Name = txtName.Text;
linObj.SubmitChanges();
}
}

protected void btnAdd_Click(object sender, EventArgs e)
{
linqStudent linObj = new linqStudent();
Student objStdebt = new Student();
objStdebt.Name = txtName.Text;
objStdebt.Roll = txtRoll.Text;
linObj.Students.InsertOnSubmit(objStdebt);
linObj.SubmitChanges();
}