In this blog we will know while inserting the same data it will display a message (Sorry! you can't take this). If we enter different data then it will display a message (You can take this) and data will be enter into the database.
Table creation
create table employee (eid int primary key identity,ename varchar(50),eaddress varchar(50))
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Insert_data_ifnot_exits._Default" %>
<!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">
<title>Untitled Page</title>
</head>
<body>
<form
id="form1"
runat="server">
<div>
</div>
<asp:Button ID="Button1"
runat="server"
Text="Availability
of name from the database"
BackColor="#FF99FF" Font-Bold="True" Width="329px"
onclick="Button1_Click" /><br />
<asp:Label ID="Labelcheck" Text="Ename" runat="server" BackColor="#FFFF99"
Width="197px" ForeColor="#FF3300"></asp:Label>
<asp:TextBox
ID="txtUserName"
runat="server"
Width="197px"></asp:TextBox>
<asp:RequiredFieldValidator
ID="RequiredFieldValidator1"
runat="server"
ControlToValidate="txtUserName" ErrorMessage="*Name Required"></asp:RequiredFieldValidator><br />
<asp:Label
ID="Label1" Text="Eaddress" runat="server" BackColor="#FFFF99"
Width="197px" ForeColor="#FF3300"></asp:Label>

Join the conversation! Your thoughts help the community grow.