Showing posts with label Delete. Show all posts
Showing posts with label Delete. Show all posts

13 March 2014

DELETE Statement in sql



The DELETE statement is used to delete rows from a table.

Syntax

DELETE FROM table_name WHERE column_name = data

Let's Create a table :
create table tbl_student(Id int,Name varchar(200))

Let's Insert Data:
insert into tbl_student values(1,'adi')
insert into tbl_student values(2,'jc')
insert into tbl_student values(3,'balu')
DELETE Statement with where

DELETE FROM tbl_student WHERE Id = 1

Output:
(1 row(s) affected)
DELETE Statement without where
DELETE FROM tbl_student
Output:
(2 row(s) affected)

21 February 2014

LINQ Deleter Query in c#.net

LINQ Deleter Query:

MydbDataContext db = new MydbDataContext();
        tbl_student stu = db.tbl_students.Single(x => x.Id == 103);
        db.tbl_students.DeleteOnSubmit(stu);
        db.SubmitChanges();


C#.net Code

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

public partial class Delete : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        MydbDataContext db = new MydbDataContext();
        tbl_student stu = db.tbl_students.Single(x => x.Id == 103);
        db.tbl_students.DeleteOnSubmit(stu);
        db.SubmitChanges();

    }
}