slinq

Download SLINQ

If you can't read please download the document

Upload: kamal-tiwari

Post on 14-Feb-2016

214 views

Category:

Documents


0 download

DESCRIPTION

LINQ TO SQL

TRANSCRIPT

using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;public partial class LinqDB : System.Web.UI.Page{ MySLinqDataContext dc = new MySLinqDataContext(); protected void Page_Load(object sender, EventArgs e) { } protected void BtnInsert_Click(object sender, EventArgs e) { shop sh = new shop(); sh.sId =Convert.ToInt32(TextBox1.Text); sh.shopnm = TextBox2.Text; sh.shopaddr = TextBox3.Text; dc.shops.InsertOnSubmit(sh); dc.SubmitChanges(); } protected void Button2_Click(object sender, EventArgs e) { //Update Button code var r = (from i in dc.shops where i.sId == Convert.ToInt32(TextBox1.Text) select i).SingleOrDefault(); r.shopnm = TextBox2.Text; r.shopaddr = TextBox3.Text; dc.SubmitChanges(); } protected void btnDelete_Click(object sender, EventArgs e) { var r = (from i in dc.shops where i.sId == Convert.ToInt32(TextBox1.Text) select i).SingleOrDefault(); dc.shops.DeleteOnSubmit(r); dc.SubmitChanges(); } protected void Button4_Click(object sender, EventArgs e) { //Search button var r = (from i in dc.shops where i.sId == Convert.ToInt32(TextBox1.Text) select i).SingleOrDefault(); TextBox2.Text=r.shopnm; TextBox3.Text=r.shopaddr; } protected void Button5_Click(object sender, EventArgs e) { //Gridview code var r = (from i in dc.shops select i); GridView1.DataSource = r; GridView1.DataBind(); }}