Skip to content

Commit

Permalink
Update transaction's code
Browse files Browse the repository at this point in the history
  • Loading branch information
smileexpression committed Jan 23, 2024
1 parent 0affd09 commit 6480eb2
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions lab15-library-management-system/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,42 @@

[mindmap](https://arronvague.github.io/Database-Systems-Laboratory/lab15-library-management-system/mindmap/mindmap.html)

**事务**

```csharp
using (MySqlConnection connection = Database.GetMySqlConnection())
{
connection.Open();

MySqlTransaction transaction = connection.BeginTransaction();

try
{
// 设置事务关联的命令
...

// 执行事务关联的命令
command1.ExecuteNonQuery();
command2.ExecuteNonQuery();
command3.ExecuteNonQuery();
command4.ExecuteNonQuery();

// 提交事务
transaction.Commit();
Console.WriteLine("借阅图书成功!");

ClearTextBox();
DataBind_Customer();
lbl_Note.Text = "Borrowed successfully!";
}
catch (Exception ex)
{
// 回滚事务
transaction.Rollback();
Console.WriteLine("借阅图书失败!");
Console.WriteLine("错误信息:" + ex.Message);
}

}
```

0 comments on commit 6480eb2

Please sign in to comment.