判断用户注册用户时用户名是否重名

时间:2013-09-01 17:04:08
【文件属性】:
文件名称:判断用户注册用户时用户名是否重名
文件大小:1KB
文件格式:TXT
更新时间:2013-09-01 17:04:08
用户名 private void button2_Click(object sender, EventArgs e) { if (this.textBox1.Text==""||this.textBox1.Text=="请输入用户名:") { MessageBox.Show("用户名不能为空!"); } string uname = this.textBox1.Text; string pwd = this.textBox3.Text; hyqpm.con.Close(); hyqpm.con.Open(); SqlCommand com = new SqlCommand("insert into admin values('"+uname+"','"+pwd+"')",hyqpm.con); if (checkuName(uname)) //判断用户名否存在 { MessageBox.Show( "用户名已存在!请重新输入:"); return; } if (this.textBox1.Text==""||this.textBox2.Text=="") { MessageBox.Show("密码不能为空!"); return; } if (com.ExecuteNonQuery()>0) { MessageBox.Show("提交成功!"); } hyqpm.con.Close(); } // 判断用户名是否存在 private bool checkuName(string name) { bool flag = false; SqlCommand com1 = new SqlCommand("select * from admin where loginid='" + this.textBox1.Text + "'", hyqpm.con); SqlDataReader dr1 = com1.ExecuteReader(); if (dr1.Read()) { flag = true; } dr1.Close(); return flag; }

网友评论

  • 不好,只是一个txt文件