LINQ



/*----Bind DropDown using LINQ----*/
DataClassesDataContext dc = new DataClassesDataContext();

//var empQurey = from c in dc.Employees
//               orderby c.EmpName
//               select new { c.EmpId, c.EmpName };
//ddlemployee.DataValueField = "EmpID";
//ddlemployee.DataTextField = "EmpName";
//ddlemployee.DataSource = empQurey;
//ddlemployee.DataBind();
/*-------OR-----------------*/
var empQurey = dc.Employees;
ddlemployee.DataValueField = "EmpID";
ddlemployee.DataTextField = "EmpName";
ddlemployee.DataSource = empQurey;
ddlemployee.DataBind();

/*----INSERT Data using LINQ----*/
DataClassesDataContext dc = new DataClassesDataContext();
Employee emp = new Employee();
//emp = dc.Employees.Where(k => k.EmpId != 0).SingleOrDefault();
emp.EmpName = TextBox1.Text;
emp.EmpSalary = TextBox2.Text;
dc.Employees.InsertOnSubmit(emp);
dc.SubmitChanges();
Response.Write("Data Saved");

No comments:

Post a Comment