[英]How I can make this insert in the MySQL Database work?
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();
}
}
}
I don't know what I do wrong here.我不知道我在这里做错了什么。
As per the Microsoft doc , the AddWithValue method require two parameters:根据Microsoft 文档,AddWithValue 方法需要两个参数:
I also emphasize the @Fildor comment, for security and legal resons you should only store hashed passwords Here is a great article about how to do it .我还强调@Fildor 评论,出于安全和法律原因,您应该只存储散列密码这是一篇关于如何做到这一点的好文章。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.