在将新数据插入我的借阅表时,如何更新我的图书表中的数量?我正在研究我们的论文,它是关于图书馆的,这个借阅功能让我很头疼。我有一个借用表格,当我按下“借用”按钮时,数据被插入到借阅表中,同时这样做,我希望我的借书表中的书籍数量可以减去或减少我在借阅中输入的数量形成。
例如。在我的SearchBook表单上,我的数量中有17个,如果我按“借用”,它将提示一个新窗口(借用表单),其中包含必须完成的详细信息,当然还有数量。点击“借用”后,数据将保存在我的借阅表中,并且我的账簿上的数量将扣除已存储到借位表的数量。
有没有办法做到这一点?我可以帮忙吗?这是我的代码:
借用表格
Dim cn As New OleDbConnection
Dim cm As New OleDbCommand
Dim myDate As Date = dtpBorrowedDate.Value
Try
With cn
.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\Library Management System\bin\debug\LMS_Database.accdb"
.Open()
End With
With cm
.Connection = cn
.CommandType = CommandType.Text
.CommandText = "INSERT INTO [Borrow] ([ID_Number], [First_Name], [Middle_Name], [Last_Name], [Course], [Year], [Contact_Number], [ISBN],[Book_Title],[Book_Author],[Category],[Year_Published], [Quantity], [Borrowed_Date], [Library_Card]) VALUES ('" & txtIDNumber.Text & "', '" & txtFirstName.Text & "', '" & txtMiddleName.Text & "', '" & txtLastName.Text & "', '" & txtCourse.Text & "','" & cboYear.Text & "', '" & txtContactNumber.Text & "', '" & txtISBN.Text & "', '" & txtBookTitle.Text & "', '" & txtBookAuthor.Text & "', '" & txtCategory.Text & "', '" & txtYearPublished.Text & "', '" & cboQuantity.Text & "', '" & dtpBorrowedDate.Value.ToString & "', '" & cboLibraryCard.Text & "')"
.Parameters.Add(New System.Data.OleDb.OleDbParameter("@ID_Number", System.Data.OleDb.OleDbType.VarChar, 30, Me.txtIDNumber.Text))
.Parameters.Add(New System.Data.OleDb.OleDbParameter("@First_Name", System.Data.OleDb.OleDbType.VarChar, 255, Me.txtFirstName.Text))
.Parameters.Add(New System.Data.OleDb.OleDbParameter("@Middle_Name", System.Data.OleDb.OleDbType.VarChar, 255, Me.txtMiddleName.Text))
.Parameters.Add(New System.Data.OleDb.OleDbParameter("@Last_Name", System.Data.OleDb.OleDbType.VarChar, 255, Me.txtLastName.Text))
.Parameters.Add(New System.Data.OleDb.OleDbParameter("@Course", System.Data.OleDb.OleDbType.VarChar, 255, Me.txtCourse.Text))
.Parameters.Add(New System.Data.OleDb.OleDbParameter("@Year", System.Data.OleDb.OleDbType.VarChar, 255, Me.cboYear.Text))
.Parameters.Add(New System.Data.OleDb.OleDbParameter("@Contact_Number", System.Data.OleDb.OleDbType.VarChar, 255, Me.txtContactNumber.Text))
.Parameters.Add(New System.Data.OleDb.OleDbParameter("@ISBN", System.Data.OleDb.OleDbType.VarChar, 255, Me.txtISBN.Text))
.Parameters.Add(New System.Data.OleDb.OleDbParameter("@Book_Title", System.Data.OleDb.OleDbType.VarChar, 255, Me.txtBookTitle.Text))
.Parameters.Add(New System.Data.OleDb.OleDbParameter("@Book_Author", System.Data.OleDb.OleDbType.VarChar, 255, Me.txtBookAuthor.Text))
.Parameters.Add(New System.Data.OleDb.OleDbParameter("@Category", System.Data.OleDb.OleDbType.VarChar, 255, Me.txtCategory.Text))
.Parameters.Add(New System.Data.OleDb.OleDbParameter("@Year_Published", System.Data.OleDb.OleDbType.VarChar, 255, Me.txtYearPublished.Text))
.Parameters.Add(New System.Data.OleDb.OleDbParameter("@Quantity", System.Data.OleDb.OleDbType.VarChar, 255, Me.cboQuantity.Text))
.Parameters.Add(New System.Data.OleDb.OleDbParameter("@Borrowed_Date", System.Data.OleDb.OleDbType.VarChar, 255, Me.dtpBorrowedDate.Value.ToString))
.Parameters.Add(New System.Data.OleDb.OleDbParameter("@Library_Card", System.Data.OleDb.OleDbType.VarChar, 255, Me.cboLibraryCard.Text))
cm.Parameters("@ID_Number").Value = Me.txtIDNumber.Text
cm.Parameters("@First_Name").Value = Me.txtFirstName.Text
cm.Parameters("@Middle_Name").Value = Me.txtMiddleName.Text
cm.Parameters("@Last_Name").Value = Me.txtLastName.Text
cm.Parameters("@Course").Value = Me.txtCourse.Text
cm.Parameters("@Year").Value = Me.cboYear.Text
cm.Parameters("@Contact_Number").Value = Me.txtContactNumber.Text
cm.Parameters("@ISBN").Value = Me.txtISBN.Text
cm.Parameters("@Book_Title").Value = Me.txtBookTitle.Text
cm.Parameters("@Book_Author").Value = Me.txtBookAuthor.Text
cm.Parameters("@Category").Value = Me.txtCategory.Text
cm.Parameters("@Year_Published").Value = Me.txtYearPublished.Text
cm.Parameters("@Quantity").Value = Me.cboQuantity.Text
cm.Parameters("@Borrowed_Date").Value = Me.dtpBorrowedDate.Value.ToString
cm.Parameters("@Library_Card").Value = Me.cboLibraryCard.Text
cm.ExecuteNonQuery()
MsgBox("Book borrowed.", MsgBoxStyle.Information, "Success!")
Me.txtIDNumber.Text = ""
Me.txtFirstName.Text = ""
Me.txtMiddleName.Text = ""
Me.txtLastName.Text = ""
Me.txtCourse.Text = ""
Me.txtContactNumber.Text = ""
Me.txtISBN.Text = ""
Me.txtBookTitle.Text = ""
Me.txtBookAuthor.Text = ""
Me.txtYearPublished.Text = ""
Me.txtCategory.Text = ""
cboQuantity.SelectedIndex = -1
cboYear.SelectedIndex = -1
cboLibraryCard.SelectedIndex = -1
Exit Sub
End With
Catch ex As Exception
MsgBox("Please fill all the details needed. ", MsgBoxStyle.Exclamation, "Error")
End Try