Private Sub btnPurchaseSave_Click(sender As Object, e As EventArgs) Handles btnPurchaseSave.Click
Dim InvNo As Integer
Dim ItmName As String
Dim ItmType As String
Dim ItmQuantity As Double
Dim ItmPurPrice As Double
Dim itmTotalCost As Double
Dim DateFormat = "dd/MM/yyyy"
Dim InvTotal As Double
InvNo = CInt(txtInvoiceNo.Text)
InvTotal = TotalCost()
Dim InvDate = Format(CDate(txtInvoiceDate.Text), DateFormat)
ConnectDatabse()
If blnPurchNew = True Then
myConnection.Open()
ObjCommand.CommandText = "Insert into Invoice (Invoice_No,Invoice_Date,Supplier_Name,Invoice_Total) values (@Invoice_No, @Invoice_Date,@Supplier_Name,@Invoice_Name)"
ObjCommand.Connection = myConnection
ObjCommand.Parameters.AddWithValue("Invoice_No", InvNo)
ObjCommand.Parameters.AddWithValue("Invoice_Date", InvDate)
ObjCommand.Parameters.AddWithValue("Supplier_Name", txtSupplierName.Text)
ObjCommand.Parameters.AddWithValue("Invoice_Total", InvTotal)
ObjCommand.ExecuteNonQuery()
ObjCommand.Dispose()
' Try
For i = 0 To DGPurchase.Rows.Count - 2
ObjCommand.CommandText = "Insert into Item_Invoice (Invoice_No,Item_Name,Item_Type,Item_Quantity,Item_Total_Cost,Item_Purchase_Price) values (@Invoice_No,@Item_Name,@item_Type, @Item_Quantity,@Item_Total_Cost,@Item_Purchase_Price)"
ObjCommand.Connection = myConnection
ItmName = DGPurchase.Rows(i).Cells(0).Value.ToString
ItmType = DGPurchase.Rows(i).Cells(1).Value.ToString
ItmQuantity = CDbl(DGPurchase.Rows(i).Cells(2).Value)
itmTotalCost = CDbl(DGPurchase.Rows(i).Cells(3).Value)
ItmPurPrice = CDbl(DGPurchase.Rows(i).Cells(4).Value)
ObjCommand.Parameters.AddWithValue("Invoice_No", InvNo)
ObjCommand.Parameters.AddWithValue("Item_Name", ItmName)
ObjCommand.Parameters.AddWithValue("Item_Type", ItmType)
ObjCommand.Parameters.AddWithValue("Item_Quantity", ItmQuantity)
ObjCommand.Parameters.AddWithValue("Item_Total_Cost", itmTotalCost)
ObjCommand.Parameters.AddWithValue("Item_Purchase_Price", ItmPurPrice)
ObjCommand.ExecuteNonQuery()
ObjCommand.Dispose()
Next i
' Catch ex As Exception
'MsgBox(ex.Message)
' End Try
MessageBox.Show("تم حفظ فاتوة المشتريات")
lblTotalCost.Text = " الاجمالي : "
clear()
blnPurchNew = False
Else
If blnPurchModify = True Then
myConnection.Open()
ObjCommand.CommandText = "UPDATE Invoice SET [email protected]_Date,[email protected]_Name,[email protected]_Total WHERE Invoice_No=" & CInt(txtInvoiceNo.Text) & " "
ObjCommand.Connection = myConnection
ObjCommand.Parameters.AddWithValue("Invoice_Date", InvDate)
ObjCommand.Parameters.AddWithValue("Supplier_Name", txtSupplierName.Text)
ObjCommand.Parameters.AddWithValue("Invoice_Total", InvTotal)
ObjCommand.ExecuteNonQuery()
ObjCommand.Dispose()
' Try
For i = 0 To DGPurchase.Rows.Count - 2
' ObjCommand.CommandText = "UPDATE Item_Invoice SET [email protected]_Name,[email protected]_Type, [email protected]_Quantity,[email protected]_Total_Cost,[email protected]_Purchase_Price WHERE [email protected]_NO"
ObjCommand.Connection = myConnection
ObjCommand.CommandText = "Update Item_Invoice Set [email protected]_Name Where [email protected]_No"
ItmName = DGPurchase.Rows(i).Cells(0).Value.ToString
ItmType = DGPurchase.Rows(i).Cells(1).Value.ToString
ItmQuantity = CDbl(DGPurchase.Rows(i).Cells(2).Value)
itmTotalCost = CDbl(DGPurchase.Rows(i).Cells(3).Value)
ItmPurPrice = CDbl(DGPurchase.Rows(i).Cells(4).Value)
ObjCommand.Parameters.AddWithValue("Invoice_No", InvNo)
ObjCommand.Parameters.AddWithValue("Item_Name", ItmName)
ObjCommand.Parameters.AddWithValue("Item_Type", ItmType)
ObjCommand.Parameters.AddWithValue("Item_Quantity", ItmQuantity)
ObjCommand.Parameters.AddWithValue("Item_Total_Cost", itmTotalCost)
ObjCommand.Parameters.AddWithValue("Item_Purchase_Price", ItmPurPrice)
ObjCommand.ExecuteNonQuery()
ObjCommand.Dispose()
Next i
MessageBox.Show("تم تعديل فاتوة المشتريات")
lblTotalCost.Text = " الاجمالي : "
clear()
blnPurchModify = False
End If
End If
myConnection.Close()
myConnection.Dispose()
ObjCommand.Dispose()
End Sub
両方のテーブルを保存して最初の "請求書"を更新することはできますが、アイテム請求書更新に関する2番目の部分の何が問題なのか分かりません。 私はエラーが発生していません。テーブルデータベースのデータが変更されずに更新の成功メッセージが表示されます。VB.NETはMSAccessデータベースのレコードを更新できません
申し訳ありませんが、長いコードのために、私はそれを明確にしたいと思いました。
ご協力いただきありがとうございます。
わかりません。また、objCommand.Disposeの呼び出しは、objCommand – Steve
を使用しているコードの最後に移動する必要があります。私は運がないとあなたが提案したものを試しました。 ObjCommand.Disposeの最後にobjCommand.Parameters.Clearと同じことをやり直してください。さらに、レコードを保存するためにInsert Statementと同じコードとループを使用していますが、正常に動作しています。 Thanks –
いいえ、DisposeはobjCommandを破棄します。 ObjectDisposed例外を受け取らないのは幸いです。 OleDbCommandに割り当てを解除するためのリソースがないことは、あなたにとって幸いです。絶対にその行を削除する必要があります。 – Steve