且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

工作但不会保存在数据库中

更新时间:2023-02-15 15:18:55

正如消息所说,你离开了括号()关闭前一个语句,调用构造函数





此外,您不需要为参数指定数据类型。

您可能希望在使用 @ 时保持一致。 br />






现在你有两个连接和两个命令。

连接你正在使用没有连接字符串。
Just as the message says, you left the parentheses () off the previous statement, the call to the constructor


Also, you don't need to specify the datatype for the parameters.
And you may want to be consistent in using the @ .



You now have two connections and two commands.
The connection you are using has no connection string.


private void btnRegister_Click(object sender,EventArgs e)

{



Login.myCon.Open();

MySqlCommand cmd = new MySqlCommand(INSERT INTO users(firstname,lastname,username,password,emailadd)VALUES('+ txtFirstName.Text + ','+ txtLastName.Text +','+ txtUserName.Text +','+ txtPassword.Text +', + txtEmailadd.Text +'),Login.myCon);

cmd.ExecuteNonQuery();

Login.myCon.Close();



MessageBox.Show(保存已完成!);

this.Hide();



登录日志=新登录();

log.Show();





这是正确答案!
private void btnRegister_Click(object sender, EventArgs e)
{

Login.myCon.Open();
MySqlCommand cmd = new MySqlCommand("INSERT INTO users (firstname, lastname, username, password, emailadd) VALUES('"+ txtFirstName.Text +"', '"+ txtLastName.Text +"', '"+ txtUserName.Text +"', '"+ txtPassword.Text +"', '"+ txtEmailadd.Text +"')",Login.myCon);
cmd.ExecuteNonQuery();
Login.myCon.Close();

MessageBox.Show("Saving is done!");
this.Hide();

Login log = new Login();
log.Show();


This is the correct answer!