不接受用户名 [英] Doesn't accept the user name
问题描述
您好,先生,
错误消息为 用户ID已存在.请选择ID"
Hi sir,
Error Msg is " User ID Already Exists. Please, Choose ID "
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
{
CustmomerDB custDB;
protected void Page_Load(object sender, EventArgs e)
{
txtfname.Focus();
btnSubmit.Attributes.Add("onclick", "return validate()");
}
protected void btnReset_Click(object sender, EventArgs e)
{
txtcustid.Text = "";
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 = "";
txtcustid.Focus();
lblmsg.Visible = false;
}
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 !";
}
}
protected void LinkButton2_Click(object sender, EventArgs e)
{
Response.Redirect("CustomerHomePage.aspx");
}
}
推荐答案
我们无法回答-这取决于您尚未提供给我们的代码:
We can''t answer that - it depends on code you haven''t given us:
ds = custDB.CustmomerDB(txtusername.Text);
大概是如果找不到用户(或者您认为确实存在)但没有CustmomerDB.CustmomerDB的代码,则无法返回该空表.在该行上放置一个断点,然后将代码放入方法中.
但是,出于善意,请停止执行以下操作:
presumably returns an empty table if the user is not found (or you think it does) but without the code for CustmomerDB.CustmomerDB we can''t tell. Put a breakpoint on that line, and follow the code into the method.
But for goodness sake, stop doing things like that:
if (ds.Tables[0].Rows.Count > 0 && ds.Tables[0].Rows[0][9].ToString() == txtusername.Text)
使用Tables[0]
几乎可以接受(虽然返回一个数据表会更好),但是使用魔术数字"选择所需的列只是造成麻烦的秘诀.请使用文本字符串或在CustmomerDB中定义的常量,以便将来的更改仍可在右侧栏中进行!
Using Tables[0]
is marginally acceptable (though returning a single datatable instead would be a better idea), but "magic numbers" to select which column you want is just a recipe for maintenance headaches. Use a text string, or a constant defined in CustmomerDB instead so that future changes still acces sthe right column!
这篇关于不接受用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!