Ok - Re-designed the database as you highlighted.
Now, I have all the 4 tables as highlighted;
TblCatType
TblTruckType
TblTruckModel
TblTruckProducts
Now,
When I update TblSales, which contains almost all the details of the product inclusive Quantity. I want to update TblTruckProducts with the quantity left at the same time.
For example,
Product A = Quantity is 5 , then a user bought 2 so remainder 3.
I want to update TblTruckProducts with Quantity = 3. So that when the form is launched it shows that 3 are left.
This is how I do my insert;
Code:
For RowID = 0 To DgvSelectedItems.Rows.Count - 1
Dim sql As String = "INSERT INTO dbo.TblSales (TransactionID, TruckType, TruckModel, CatType, ProductID, ProductName, PriceperItem, Quantity, FullAmount, Username, SalesDatetime) " & _
"VALUES (@TransactionID, @TruckType, @TruckModel, @CatType, @ProductID, @ProductName, @PriceperItem, @Quantity, @FullAmount, @Username, @SalesDatetime)"
Dim cmd As New SqlCommand(sql, nextConn)
With cmd.Parameters
.AddWithValue("@TransactionID", TransactionID)
.AddWithValue("@TruckType", Me.DgvSelectedItems.Rows(RowID).Cells(0).Value)
.AddWithValue("@TruckModel", Me.DgvSelectedItems.Rows(RowID).Cells(1).Value)
.AddWithValue("@CatType", Me.DgvSelectedItems.Rows(RowID).Cells(2).Value)
.AddWithValue("@ProductID", Me.DgvSelectedItems.Rows(RowID).Cells(3).Value)
.AddWithValue("@ProductName", Me.DgvSelectedItems.Rows(RowID).Cells(4).Value)
.AddWithValue("@PriceperItem", Me.DgvSelectedItems.Rows(RowID).Cells(5).Value)
.AddWithValue("@Quantity", Me.DgvSelectedItems.Rows(RowID).Cells(6).Value)
.AddWithValue("@FullAmount", Me.DgvSelectedItems.Rows(RowID).Cells(8).Value)
.AddWithValue("@Username", Me.ToolStripTextBox2.Text)
.AddWithValue("@SalesDatetime", DateTime.Now)
End With
cmd.ExecuteNonQuery()
Next RowID
Anyway can I incorporate it here - with an update to the Quantity to TblTruckProducts ...
Thanks