private void button1_click(object sender, EventArgs e)
{
conn.Open();
if (textBox3.Text.Trim() == textBox4.Text.Trim() && IsValidEmail(textBox1.Text))
{
MySqlCommand comm = conn.CreateCommand();
comm.CommandText = "INSERT into users(userName, password, email) values(@user,@pass,@mail)";
MySqlTransaction tx = conn.BeginTransaction();
comm.Transaction = tx;
try
{
comm.Parameters.AddWithValue("@user", MySqlDbType.Text).Value = textBox2.Text;
comm.Parameters.AddWithValue("@pass", MySqlDbType.Text).Value = textBox3.Text;
comm.Parameters.AddWithValue("@mail", MySqlDbType.Text).Value = textBox1.Text;
comm.ExecuteNonQuery();
tx.Commit();
}
catch
{
MessageBox.Show("Error!");
}
finally
{
conn.Close();
}
}
}
我不知道我做错了什么。
1条答案
按热度按时间dced5bon1#
根据Microsoft doc,AddWithValue方法需要两个参数:
我还强调了@Fildor的评论,出于安全和法律的原因,您应该只存储散列密码Here is a great article about how to do it。
And here, why you should do it