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()
没有出现错误,所以我不太确定出了什么问题
答案 0 :(得分:2)
你从未执行过该陈述。你需要:
con.Open()
cmd.ExecuteNonQuery()
con.Close()