我有两个程序运行顺利命名 update_students
以及 insert_payment
.
Sub insert_payment()
con.open
Using cmd as New MySQLCommand
With cmd
.Connection = con
.CommandType = CommanType.Text
.CommandText = "INSERT INTO tblpayment(stud_id,payment_amount) VALUES (@stud_id,@payment_amount);"
.Parameters.AddWithValue("@stud_id", txtid.text)
.Parameters.AddWithValue("@payment_amount", txtpay.text)
.ExecuteNonQuery()
End With
con.Close()
End Using
End Sub
和
Sub update_students()
con.open
Using cmd as New MySQLCommand
With cmd
.Connection = con
.CommandType = CommanType.Text
.CommandText = "UPDATE tbl_stud SET tuition_status=@tuition_status,address_school=@address_school;"
.Parameters.AddWithValue("@ID", txtid.text)
.Parameters.AddWithValue("@tuition_status", txtns.text)
.Parameters.AddWithValue("@address_school", txtadd.text)
.ExecuteNonQuery()
End With
con.Close()
End Using
End Sub
现在在addbuttonclick事件中,我调用了两个过程来执行。虽然我没有遇到错误。
我的问题是,我想知道这两个过程是否完全同时执行。如果第1个或第2个或两者都遇到错误,它应该通知,那么插入和更新都不会执行。
我这样做是因为我想通过同步插入和更新两个表来添加/更新它们。
对不起,我英语不好。我希望这里有人能帮我。
提前谢谢。
1条答案
按热度按时间nwlqm0z11#
这是我做的,而且很有效。
我担心如果这个代码不干净,不能使用。有什么建议吗?