DELETE RECORD OF DATABASE


CodeFile
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient ;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class DeleteRecord : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection("Trusted_Connection=true;DataBase=Praveen_DataBase");
        SqlCommand cmd = new SqlCommand("Delete from Table1 where Roll=@Roll", con);
        SqlParameter obj = new SqlParameter("@Roll", DbType.Int32.ToString());
        obj.Value = TextBox1.Text;
        cmd.Parameters.Add(obj);
        con.Open();
        cmd.ExecuteNonQuery();
        Label1.Text = "Record is deleted";
        con.Close();
       
    }
}

0 comments:

Post a Comment