提问人:siwa86 提问时间:9/17/2023 最后编辑:siwa86 更新时间:9/17/2023 访问量:52
如何使用 vb.net 刷新或重新加载 datagrdiview 中的绑定源
How to refresh or reload binding source in datagrdiview with vb.net
问:
更新后,我试图调用“loaddata”,但datagridview中的结果不匹配,如果我关闭调试表单,然后重新调试表单,那么新的datagridview视图的结果是合适的。代码有问题吗?
谢谢
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
更新 Capture1 之前
更新后捕获2
答: 暂无答案
评论
CommandBuilder and adapter
a new binding would not be necessary
QtyStock