如何一键添加两个表中的数据并同时删除数据?

How to add data in two tables and delete data at the same time using one button?

提问人:Jiyu 提问时间:12/6/2022 更新时间:12/6/2022 访问量:37

问:

“我的学生注册表中有问题,我想将我的学生信息插入到我的不同数据库中。

学生信息表

ICT、ABM和HE课程表

我还想插入、更新、删除这两个不同的数据库中插入的两个数据,只需一个按钮即可在 vb.net 中一个表单中插入”

connect()



if txtStudID = "" and txtF.text = "" and txtM.text = "" and txtS.text = "" then



    messagebox.show("Please Complete the Data")



else



    comm.Connection =conn



    comm.Commandtext = "INSERT into MyDatabase values ('" & txtStudID.text & "', '" & txtF.text & "', '" & txtM.text & "', '" & txtS.text & "', '" & dtpDOB.text & "', '" & cboGender.text & "', '" & txtAge.text & "', '" & cboProg.text & "', '" & cboYr.text & "', '" & Source.text & "', '" & txtPhone.text & "', '" & txtEmail.text & "', '" & txtAddress.text & "', '" & RD.text & "')"



    comm.ExecuteNonQuery()



    populate()



    Myclear()



end if 







'to the second table







if cboProg.Text = ICT then



    comm.Connection =conn



    comm.Commandtext = "INSERT into ICT values ('" & txtStudID.text & "', '" & txtF.text & "', '" & txtM.text & "', '" & txtS.text & "', '" & dtpDOB.text & "', '" & cboGender.text & "', '" & txtAge.text & "', '" & cboProg.text & "', '" & cboYr.text & "', '" & Source.text & "', '" & txtPhone.text & "', '" & txtEmail.text & "', '" & txtAddress.text & "', '" & RD.text & "')"



    comm.ExecuteNonQuery()



    messagebox.show("Successfully Registered as an ICT STUDENT!")



elseif cboProg.Text = ABM then



    comm.Connection =conn



    comm.Commandtext = "INSERT into ABM values ('" & txtStudID.text & "', '" & txtF.text & "', '" & txtM.text & "', '" & txtS.text & "', '" & dtpDOB.text & "', '" & cboGender.text & "', '" & txtAge.text & "', '" & cboProg.text & "', '" & cboYr.text & "', '" & Source.text & "', '" & txtPhone.text & "', '" & txtEmail.text & "', '" & txtAddress.text & "', '" & RD.text & "')"



    comm.ExecuteNonQuery()



    messagebox.show("Successfully Registered as an ABM STUDENT!")
elseif cboProg.Text = HE then
    comm.Connection =conn
    comm.Commandtext = "INSERT into HE values ('" & txtStudID.text & "', '" & txtF.text & "', '" & txtM.text & "', '" & txtS.text & "', '" & dtpDOB.text & "', '" & cboGender.text & "', '" & txtAge.text & "', '" & cboProg.text & "', '" & cboYr.text & "', '" & Source.text & "', '" & txtPhone.text & "', '" & txtEmail.text & "', '" & txtAddress.text & "', '" & RD.text & "')"



    comm.ExecuteNonQuery()



    messagebox.show("Successfully Registered as an HE STUDENT!")



    END IF
vb.net 表单 visual-studio-2010 crud ms-access-2007

评论

0赞 Hursey 12/7/2022
我有问题。你真的需要解释这个问题。究竟什么对你不起作用,向我们提供遇到的任何异常的详细信息,或者清楚地解释这如何不符合要求。你给我们的代码几乎没有什么可以快速浏览的。1) 了解如何参数化 sql 命令。周围有很多例子,很多在这个网站上。2) 阅读 Using 子句以及它如何应用于实现 IDisposable 的类。虽然这些建议都不能解决问题,但它将是更健壮的代码
0赞 Community 12/7/2022
请提供足够的代码,以便其他人可以更好地理解或重现问题。

答: 暂无答案