SqlConnection con = new SqlConnection("");//括号里面写上连接字符串
con.Open();
string sql ="select count(*) from yonghu where uid="+int.Parse(this.TextBox1.Text);//uid是什么类型,假设为整形,如果是字符串加单引号
SqlCommand cmd = new SqlCommand(sql,con);
int row = (int32)cmd.ExecuteScalar()//row大于等于1,有重复结构
SQL查询yonghu表里的uid字段是否与TextBox1相同
String.Format("select uid from yonghu where uid={0}",TextBox1.Text)
这里一般使用参数化查询,防止SQL诸如攻击,但就你目前水平,以上语句足矣
if(相同的条数>0)
if(cmd.ExecuteScalar>0)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
//查找是否有重复用户名
List
if(models != null && models.Count > 0){
lbl_UID_tips.Text = "注册用户名重复";
return;
}
//添加用户名或密码
Model.Yonghu model = new Model.Yonghu();
model.Uid = TextBox1.Text.Trim();
model.Pass = TextBox2.Text.Trim();
BLLServices.Yonghu.Insert(model);
//用户登录
if(BLLServices.Yonghu.UserLogin(TextBox1.Text.Trim(),TextBox2.Text.Trim())){
lbl_LOGIN_tips.Text = "登录失败,请核对用户名或密码";
return;
}
Response.Redirect("~/",True); //登录成功,返回主页
}