Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

While i am click on submit button every time it show the Error is "User ID Already Exists. Please, Choose ID "

C#
protected void btnSubmit_Click(object sender, EventArgs e)
   {
       try
       {
           string dob = ddlmm.Text + "/" + ddldd.Text + "/" + ddlyyyy.Text;
           DataSet ds = new DataSet();
           custDB = new CustmomerDB();
           int success = 0;
           ds = custDB.CheckExistingUser(txtusername.Text);
          if (ds.Tables[0].Rows.Count > 0 && ds.Tables[0].Rows[0][9].ToString() == txtusername.Text)

           {
               success = 1;
               lblmsg.Visible = true;
               lblmsg.ForeColor = Color.Red;
               lblmsg.Text = "User Name Allready Exists. Choose Another UserName!";

           }
           else if (success == 0)
           {
               lblmsg.Visible = true;
               success = custDB.AddNewCustomer(txtcustid.Text.Trim(), 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());
               lblmsg.Visible = true;
               lblmsg.ForeColor = Color.Green;
               lblmsg.Text = "New User Connection Added Succesfully !!";
           }
       }
       catch (Exception ex)
       {
           lblmsg.ForeColor = Color.Red;
         lblmsg.Text = "User ID Already Exists. Please, Choose ID !";

       }
Posted

Because you catch general Exception, so if your code have any error in try{}, it catch error in catch{}, not identify the specific error. If you want to add new User,in SQL Management, you can set User ID is primary key, and set Properties: Identity Specification: Yes. Isdentity: Yes. Isdentity Increment:1. Identity Seed:1 .. And when you add new User, you don't interested in UserID. UserID will automatically create. And when you add new User, your code must be edit following:
success = custDB.AddNewCustomer( 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());


And
txtcustid.Text.Trim(),
is not need.
P/s: sorry because of my english.
 
Share this answer
 
Debug the code and see what the exception really tells you. Did you do that?

Check on following line,

C#
ds = custDB.CheckExistingUser(txtusername.Text);
 
Share this answer
 
v2
Check the exception what error you are getting.

add below line in catch block.
C#
try
{
}
catch (Exception ex)
{
   lblmsg.ForeColor = Color.Red;
   lblmsg.Text = ex.StackTrace + "<br>User ID Already Exists. Please, Choose ID !";

}</br>


And after this you will be able to know what error you are getting here.
 
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