简体   繁体   English

ASP.NET C#-多个MySQL事务

[英]ASP.NET C# - Multiple MySQL transactions

I have the following MySQL tables: 我有以下MySQL表:

tests:
test_id (PK, AI), author_id (FK), module_id (FK), name

questions:
question_id (PK, AI), module_id (FK), author_id (FK), approved, question, type

answers:
answer_id (PK, AI), question_id (FK), answer, correct

tests_questions:
id (PK, AI), test_id (FK), question_id (FK)

I'm trying to implement a facility whereby a user can create a test that has n number of questions (depending on a DropDownList value). 我正在尝试实现一种功能,通过该功能,用户可以创建具有n个问题的测试(取决于DropDownList值)。 Each question has one or more answers. 每个问题都有一个或多个答案。

So far, I've got a page (create_test.aspx) for the user to enter the test details + select the number of questions. 到目前为止,我已经有了一个页面(create_test.aspx)供用户输入测试详细信息并选择问题数量。

I intend to have a Button_Click event whereby the user is redirected to another page (create_test2.aspx) to enter the details for Question 1 + linked answers. 我打算有一个Button_Click事件,借此将用户重定向到另一个页面(create_test2.aspx),以输入问题1 +链接答案的详细信息。 On the same page, within a Button_Click event, this is repeated for the n number of questions. 在同一页面上的Button_Click事件中,对n个问题重复此操作。

However, I'm not sure when exactly I should write to the database and if I should store all the details somehow and write all the data at the end. 但是,我不确定何时应该确切地写入数据库,以及是否应该以某种方式存储所有细节并最后写入所有数据。 Any help please? 有什么帮助吗?

I could insert a row in the 'tests' table on the initial page's Button_Click event and then insert each question/answers on each subsequent Button_Click event, however, what happens if the user leaves the page halfway through entering the questions? 我可以在初始页的Button_Click事件的“测试”表中插入一行,然后在随后的每个Button_Click事件中插入每个问题/答案,但是,如果用户在输入问题的途中离开页面,会发生什么情况? So I imagine this is not a sensible option? 所以我想这不是一个明智的选择?

听起来像是SQL中存储过程的完美用例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM