gpt4 book ai didi

mysql - SQL "successful"但不更新数据库?

转载 作者:行者123 更新时间:2023-11-29 07:52:26 27 4
gpt4 key购买 nike

lblMessage 说它已注册,但是当我检查数据库时没有记录。

下面是我的代码:

Try
con = New MySqlConnection("Server=localhost;Database;Uid=root;Pwd=;")
Using cmd = New MySqlCommand("START TRANSACTION; INSERT INTO account_table(acc_user, acc_pass, acc_mail, acc_ques, acc_ans, acc_priv) VALUES( @p3, @p4, @p5, @p6, @p7, 'user'); SELECT LAST_INSERT_ID(acc_id) FROM account_table; INSERT INTO patient_table(acc_id, pat_fname, pat_lname) VALUES (LAST_INSERT_ID(), @p1, @p2); COMMIT;", con)
cmd.Parameters.AddWithValue("@p1", firstname.Value.ToString)
cmd.Parameters.AddWithValue("@p2", lastname.Value.ToString)
cmd.Parameters.AddWithValue("@p3", username.Value.ToString)
cmd.Parameters.AddWithValue("@p4", password.Value.ToString)
cmd.Parameters.AddWithValue("@p5", email.Value.ToString)
cmd.Parameters.AddWithValue("@p6", quest.Value.ToString)
cmd.Parameters.AddWithValue("@p7", answer.Value.ToString)
con.Open()
End Using
lblMessage.Text = "Registered!"
Catch ex As Exception
lblMessage.Text = "The username or email appears to be taken."
End Try
con.Close()

没有出现错误,所以我不太确定出了什么问题

最佳答案

您从未执行过该语句。您需要:

con.Open()
cmd.ExecuteNonQuery()
con.Close()

关于mysql - SQL "successful"但不更新数据库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26080641/

27 4 0