0

After the update I tried to recall "loaddata" but the result in the datagridview does not match if I close the debug form and then re-debug the form then the result of the new datagridview view is appropriate. Is there something wrong with the code.

Thanks

Private BindingSource1 As BindingSource = Nothing
Private ResultList As IEnumerable(Of ProductOut) = Nothing
Private Sub loaddata()
        Using conn = New OleDbConnection(connectionString)
            conn.Open()
            resultList = conn.Query(Of ProductOut)("SELECT p.ProductId, p.ProductName,p.Price,p.Qty,s.QtyStock FROM ProductOut p INNER JOIN StockProduct s ON s.ProductId = p.ProductId").ToList()
            conn.Close()
        End Using
        bindingSource1 = New BindingSource With {.DataSource = New BindingList(Of ProductOut)(CType(resultList, IList(Of ProductOut)))}
        DataGridView1.DataSource = bindingSource1
    End Sub
 Private Sub BtnUpdate_Click(sender As Object, e As EventArgs) Handles BtnUpdate.Click
        ' Change quantity here.
  Dim product = GetProduct()
  ElseIf product IsNot Nothing Then
                ' Update product's quantity.
                product.Qty += CInt(NumericUpDownQTY.Value)
                DataGridView1.Refresh()
  conn.Open()
                    Try
                        Dim count2 As Integer = conn.Execute("UPDATE StockProduct INNER JOIN ProductOut On (StockProduct.ProductId = ProductOut.ProductId) Set StockProduct.QtyStock = (StockProduct.QtyStock-(@Param1-ProductOut.Qty)), StockProduct.QtyOut = (StockProduct.QtyOut+(@Param2-ProductOut.Qty)) WHERE ProductOut.Productid = @PARAM3;",
                        New With {
                            Key .param1 = product.Qty,
                            Key .param2 = product.Qty,
                            Key .param3 = product.ProductId})
                    Dim count As Integer = conn.Execute("UPDATE ProductOut SET
                    Qty = @param1
                    WHERE ProductId = @param2",
                        New With {
                            Key .param1 = product.Qty,
                            Key .param2 = product.ProductId})
                   MessageBox.Show("successfully")
                    loaddata()
                    Catch ex As Exception
                        MessageBox.Show(ex.Message, "POS", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
                    End Try
            End If
        End Using
    End Sub

before update Capture1

before update Capture1

AFTER UPDATE Capture2

AFTER UPDATE Capture2

7
  • Does this answer your question? update database from data grid view in vb.net as you see you update the datagriedview and the transfer the chages by updating the adapter Commented Sep 17, 2023 at 14:40
  • @nbk , thanks for your response, which you mentioned using CommandBuilder and adapter but I use dapper to bindinglist then to bindingsource then binding to datagridview Commented Sep 17, 2023 at 14:44
  • ok that you didn't write in your question, but you have updated the datagridview already so you are alrey upto dazr and a new bindibg would not be necessary Commented Sep 17, 2023 at 15:01
  • @nbk , Thank you for the response, sorry I was late in replying. a new binding would not be necessary only the QtyStock column is not up to date and and the column comes from the inner join . So there's a problem there so I have to reload or refresh again Commented Sep 18, 2023 at 2:30
  • That is because ,you update only one column, make it for both columbs in one go Commented Sep 18, 2023 at 6:22

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.