已使用ID [英] Use ID Already Exist

查看:72
本文介绍了已使用ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



每次我单击提交"按钮时,都会显示错误消息:用户ID已经存在.请选择ID".

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 !";

       }

推荐答案

因为您捕获了一般的Exception,所以如果您的代码在try {}中有任何错误,它将在catch {}中捕获错误,而不是识别具体错误.如果要添加新用户,则可以在SQL管理中将用户ID"设置为主键,并设置属性":身份规范:是".身份:是的.身份增量:1.身份种子:1..并且,当您添加新用户时,您对UserID不再感兴趣. UserID将自动创建.并且当您添加新用户时,必须按照以下步骤编辑您的代码:
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(),

.
P/s:抱歉,由于我的英语.

is not need.
P/s: sorry because of my english.


调试代码,看看异常真正告诉您什么.你这样做了吗?

检查以下行,

Debug the code and see what the exception really tells you. Did you do that?

Check on following line,

ds = custDB.CheckExistingUser(txtusername.Text);


检查异常,您将得到什么错误.

在catch块中添加以下行.
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.


这篇关于已使用ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆