February 3, 2011

Delete data from DB Using LINQ to SQl

How to use Linq in ASP.NET App  refer my below post

To Delete data from DB , below is the code using LINQ


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default8.aspx.cs" Inherits="Default8" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <form id="form1" runat="server">
      <asp:GridView ID="GridView1" runat="server"/>


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Default8 : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
        DataClasses2DataContext db = new DataClasses2DataContext();

//To delete the record
        var obj = from o in db.AdminInfos
                      where o.sLoginId=="TestLinq"
                      select o;


//to get all the records from the table
        var results = from o in db.AdminInfos
                      select o;
        GridView1.DataSource = results;

No comments:

Post a Comment