Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
Hi,
 
While i am click on submit button every time it show the Error is "User ID Already Exists. Please, Choose ID "
 
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 10-Oct-12 19:04pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Debug the code and see what the exception really tells you. Did you do that?
 
Check on following line,
 
ds = custDB.CheckExistingUser(txtusername.Text);
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Check the exception what error you are getting.
 
add below line in catch block.
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.
  Permalink  
v2

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

  Print Answers RSS
0 Maciej Los 350
1 OriginalGriff 283
2 Nguyen.H.H.Dang 230
3 Sergey Alexandrovich Kryukov 230
4 Peter Leow 195


Advertise | Privacy | Mobile
Web04 | 2.8.140709.1 | Last Updated 11 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid