Home > Net >  Check the registered user name repeated winform window procedure
Check the registered user name repeated winform window procedure

Time:02-21

I use a winform vs2012 design registration login window, link table column name is "user name" password ", "the following is the sign up button code:
Private void button2_Click (object sender, EventArgs e)
{
If (textBox1. Text=="" | | textBox2. Text==" ")
MessageBox. Show (" user name or password may not be empty ", "warning");
The else
{
SqlConnection conn=new SqlConnection (" Data Source=(local); Initial Catalog=log; Integrated Security=True ");
Conn. The Open ();
SqlCommand CMD=new SqlCommand (" select * from the log where user name='" + textBox1. Text. The Trim () + "' and password='" + textBox2. Text. The Trim () + "' ", conn);
SqlDataReader SDR=CMD. ExecuteReader ();
The SDR. The Read ();
If (SDR) HasRows)
MessageBox. Show (" the user name already exists ", "warning");
The else
{
The SDR. The Close ();
String myInsert="insert into the log (username, password) values ('" + textBox1. Text + "', '" + textBox2. Text +") ";
SqlCommand myCom=new SqlCommand (myInsert, conn);
MyCom. ExecuteNonQuery ();
Conn. Close ();
Conn. The Dispose ();
MessageBox. Show (" registration ");
}
}
Running result is only a user name and password and completely before phase will report to repeat at the same time, if the password is different can register at will, can you tell me how to change the code? Also please bosses solutions, first thank you

CodePudding user response:

Registration without authentication codes, query the user name exists
  •  Tags:  
  • C#
  • Related