Hello all, I have built a logic that if i enter duplicate value i should get Message like:"UserName already exists,try another name" but i am getting different message:"Violation of UNIQUE KEY constraint 'UserName'. Cannot insert duplicate key in object 'Login'. The statement has been terminated." In table Login UserName set as Unique key. Here is the code:
protected void BtnSubmit_Click(object sender, EventArgs e)
{
if (!Page.IsValid)
return;
NewuserBAL NUB = new NewuserBAL();
int intResult = 0;
string UserName = TxtUserName.Text;
string Password = PWD.Text;
string EmailId = Email.Text;
try
{
intResult=NUB.newinsert(UserName, Password, EmailId);
if (intResult > 0)
lbldisplay.Text = "New Account Created Successfully";
else
lbldisplay.Text = "UserName[<b>"+TxtUserName.Text+"</b>] already exists,try another name";
TxtUserName.Text = "";
PWD.Text = "";
CnfrmPwd.Text = "";
Email.Text = "";
}
catch(Exception ee)
{
lbldisplay.Text = ee.Message.ToString();
}
finally
{
NUB = null;
}
Please somebody help me where i made mistake.
Thanks, Masum