DELETE Query
DELETE Query
The SQL DELETE Query is used to delete the existing records from a table.Delete Data in Table in Database.WHERE clause with a DELETE query to delete the selected rows, otherwise all the records would be deleted.
library - using System.Data.SqlClient;
Syntax:
Delete from student(table) where rn = ' " + TextBox1.Text+ " ' ;
1. Design
2.Write code on Button_Click2
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
SqlConnection cn;
SqlCommand cm;
SqlDataReader dr;
protected void Page_Load(object sender, EventArgs e)
{
}
The SQL DELETE Query is used to delete the existing records from a table.Delete Data in Table in Database.WHERE clause with a DELETE query to delete the selected rows, otherwise all the records would be deleted.
library - using System.Data.SqlClient;
Syntax:
Delete from student(table) where rn = ' " + TextBox1.Text+ " ' ;
1. Design
2.Write code on Button_Click2
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
SqlConnection cn;
SqlCommand cm;
SqlDataReader dr;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button2_Click(object sender, EventArgs e)
{
string cs = @"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True";
cn = new SqlConnection(cs);
cn.Open();
string k = "delete from stu where rn='"+TextBox1.Text+"' ";
cm = new SqlCommand(k,cn);
cm.ExecuteNonQuery();
}
}
3. Output: