Dim i As Integer For i = 0 To DataGridView2.Rows.Count - 1 Dim barcode As String = DataGridView2.Rows(i).Cells(1).Value Dim buyprice As Decimal = DataGridView2.Rows(i).Cells(2).Value Dim saleprice As Decimal = DataGridView2.Rows(i).Cells(3).Value Dim itemcount As Integer = DataGridView2.Rows(i).Cells(4).Value Dim cmd3 As New OleDb.OleDbCommand sql = "insert into recieptdetails" & _ "(recieptID,barcode,itemcount,buyprice,saleprice)" & _ "values" & _ "( :0 ,:1 ,:2 ,:3 ,:4 )" cmd3.Connection = myconnection cmd3.Transaction = mytransaction cmd3.CommandText = sql cmd3.Parameters.AddWithValue(":0", recieptID) cmd3.Parameters.AddWithValue(":1", barcode) cmd3.Parameters.AddWithValue(":2", itemcount) cmd3.Parameters.AddWithValue(":3", buyprice) cmd3.Parameters.AddWithValue(":4", saleprice) cmd3.ExecuteNonQuery() cmd3.Dispose() Next mytransaction.Commit() mytransaction.Dispose() myconnection.Dispose() DataGridView2.Rows.Clear() Catch ex As Exception MsgBox(ex.Message) If mytransaction IsNot Nothing Then mytransaction.Rollback() End If If myconnection IsNot Nothing Then If myconnection.State = ConnectionState.Open Then myconnection.Close() End If End If End Try End Sub
recieptID
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)