Click here to Skip to main content
15,881,689 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
While i enter the details for employee registration this error mas i found, please check the below code and make the correction please,

User ID Already Exists. Please, Choose ID



C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Drawing;

public partial class temp_index : System.Web.UI.Page
{
    EmployeeDB empDB;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (System.Convert.ToString(Session["un"]) != "")
        { }
        else { Response.Redirect("HomePage.aspx"); }

        txtfname.Focus();
        btnSubmit.Attributes.Add("onclick", "return validate()");

    }
    protected void btnReset_Click(object sender, EventArgs e)
    {
        txtfname.Text = "";
        txtmname.Text = "";
        txtlname.Text = "";
        ddldd.Text = "DD";
        ddlmm.Text = "MM";
        ddlyyyy.Text = "YYYY";
        ddlgender.Text = "Select";
        txtaddress.Text = "";
        txtmobile.Text = "";
        txtphone.Text = "";
        txtusername.Text = "";
        txtpwd.Text = "";
        txtsalary.Text = "";
        txtfname.Focus();
        lblmsg.Visible = false;
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        try
        {

            string dob = ddlmm.Text + "/" + ddldd.Text + "/" + ddlyyyy.Text;
            empDB = new EmployeeDB();
            int success = 0;
            success = empDB.AddNewEmployee(txtfname.Text.Trim(), txtmname.Text.Trim(), txtlname.Text.Trim(), dob, ddlgender.Text, txtaddress.Text.Trim(), txtmobile.Text.Trim(), txtphone.Text.Trim(), txtusername.Text.Trim(), txtpwd.Text.Trim(),txtsalary.Text.Trim());
            lblmsg.Visible = true;
            lblmsg.ForeColor = Color.Green;
            if (success > 0)
                lblmsg.Text = "Employee Registration Saved Succesfully !!";
            else
                lblmsg.ForeColor = Color.Red;
                //lblmsg.Text = "Error Occured !!";
        }
        catch (Exception ex)
        {
            lblmsg.ForeColor = Color.Red;
            lblmsg.Text = ex.ToString();
        }
    }
    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        Response.Redirect("AdminHomePage.aspx");
    }
}
Posted
Comments
Sandeep Mewara 8-Sep-12 5:05am    
What is the final query executing?
whats in AddNewEmployee?
Mohamed Mitwalli 8-Sep-12 5:07am    
Put break point and debug your code see when this occur

put break in the below line and debug plz,

I think this function have the code!!!!

C#
success = empDB.AddNewEmployee(txtfname.Text.Trim(), txtmname.Text.Trim(), txtlname.Text.Trim(), dob, ddlgender.Text, txtaddress.Text.Trim(), txtmobile.Text.Trim(), txtphone.Text.Trim(), txtusername.Text.Trim(), txtpwd.Text.Trim(),txtsalary.Text.Trim());
 
Share this answer
 
v2
Hi,

You can easily fix this error by removing primary key from the table or create a unique user id for each employee record.
If you can post empDB.AddNewEmployee function code we can easily figure out the root cause.

Thanks!!!
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900