I have a datatable that contain 4 records, These 4 records r also in the database
when second time i m tring to insert that data
here i m getting an error like this
Violation of PRIMARY KEY constraint 'PK_VMIS_30'. Cannot insert duplicate key in object 'VMIS_30'. The statement has been terminated.
I want to show like an message box or in the response.write("DATA ALREADY EXIXTS") statement, Post solution for this
Thanks in advance
Loading
Satyapriya NayakPosted Dec 23, 2011, 4:59 AM
Try this...
using System;
using System.Configuration;
using System.Data;
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;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlCommand com ;
string str = null;
protected void Button1_Click(object sender, EventArgs e)
{
namecheck();
}
public void namecheck()
{
SqlConnection con = new SqlConnection(connStr);
con.Open();
str = "select count(*)from employee where ename='" + txtUserName.Text + "'";
com = new SqlCommand(str, con);
int count = Convert.ToInt32(com.ExecuteScalar());
if (count > 0)
{
lblMessage.Text = "Sorry! you can't take this username";
}
else
{
lblMessage.Text = "You can take this username";
}
}
}
Thanks