EnjoySharePoint YouTube Channel

Delete record using enterprise library in Asp.Net

In this article we will discuss how to delete a record using enterprise library in Asp.Net.

Get Office 365 Enterprise E3 Or Business Premium Subscription & Try out all the features

You should read how to use enterprise library in Asp.Net before starting this article.

You can also check my previous posts on

Null Coalescing Operator in C#.Net

Set default focus in Asp.net

Method Overloading in C#.Net.

In this post we will see, whenever a user put an id in the textbox and click on submit, the data should get deleted from the database. Below is the full code:

Store Procedure:

@Empid int

DELETE FROM EmloyeeDetail WHERE Empid=@Empid


.aspx code:

Emp Id
<asp:TextBox ID=”txtEmpid” runat=”server”></asp:TextBox>
<asp:Button ID=”btnDelete” runat=”server” Text=”Delete” OnClick=”btnDelete_Click” />
<asp:Label ID=”lblResult” runat=”server” Text=”Label”></asp:Label>

.aspx.cs 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.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using Microsoft.Practices.EnterpriseLibrary.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Common;
using System.Data;

public partial class DeleteData : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)
protected void btnDelete_Click(object sender, EventArgs e)
Database db = DatabaseFactory.CreateDatabase(“connection”);
DbCommand dbCommand = db.GetStoredProcCommand(“[DeleteEmployeData]”);
db.AddInParameter(dbCommand, “@Empid”, DbType.Int32, Convert.ToInt32(txtEmpid.Text));

int result = db.ExecuteNonQuery(dbCommand);
if (result > 0)
lblResult.Text = “Record deleted successfully!”;
lblResult.Text = “Some error occured!”;
catch (Exception ex)

Check out Best Alternative to InfoPath -> Try Now
You May Also like the Following SharePoint Tutorials:

About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

View all posts by Bijay Kumar →