更新数据库后刷新Datagridview

时间:2017-01-04 15:28:20

标签: vb.net datagridview

我正在更新表单中的数据库并再次加载datagridview但datagridview没有更新。我试过的代码如下。

这是我的销售条目表单中的代码,如果已售出商品,则应减少数量,但在保存销售后,库存不会在网格中更新。

 Private Sub loadallitembtch()
    dgvsearchitem.ScrollBars = ScrollBars.Vertical
    On Error Resume Next
    con = New OleDbConnection(connectionString)
    con.Open()

    Dim ds As DataSet = New DataSet
    Dim adapter As New OleDb.OleDbDataAdapter

    sqlstr &= " Select "
    sqlstr &= "   im.iname & ' ' & MfgComTab.comname as [Item], "
    sqlstr &= "   imd.batch As Batch, "
    sqlstr &= "   imd.pscheme As [P Scheme], "
    sqlstr &= "   imd.sscheme As [S Scheme], "
    sqlstr &= "   ROUND(Sum(IIF(txm.ttype = 'S', -txd.iqty, IIF(txm.ttype = 'P', txd.iqty * "
    sqlstr &= "   im.unitratio, IIF(txm.ttype = 'SR', txd.iqty, IIF(txm.ttype = 'PR', "
    sqlstr &= "   -txd.iqty * im.unitratio, IIF(txm.ttype = 'OP', txd.iqty * im.unitratio, "
    sqlstr &= "   0)))))), 2) As [Stock], "
    sqlstr &= "   Unit.unitname As Units, "
    sqlstr &= "   imd.itemid, "
    sqlstr &= "   im.stax as [Tax], "
    sqlstr &= "   imd.prate / im.unitratio As [P Rate], "
    sqlstr &= "   imd.srate / im.unitratio As [Rate] "
    sqlstr &= " From "
    sqlstr &= "   (((([Transaction_Details] As txd Inner Join "
    sqlstr &= "   [Transaction_Mas_Tab] As txm On txd.txid = txm.txid) Inner Join "
    sqlstr &= "   IMasterDetails As imd On txd.itemid = imd.itemid) Inner Join "
    sqlstr &= "   Imaster As im On imd.icode = im.icode) Inner Join "
    sqlstr &= "   Unit On Unit.unitcode = im.sunit) Inner Join "
    sqlstr &= "   MfgComTab On im.mccode = MfgComTab.mccode "
    sqlstr &= " Where "
    sqlstr &= "   txm.billdate Between @date1 And @date2 And "
    sqlstr &= "   txm.isdeleted = 'N' And "
    sqlstr &= "   im.comcode = @comcode "
    sqlstr &= " Group By "
    sqlstr &= "   im.iname, imd.batch, imd.pscheme, imd.sscheme, Unit.unitname, imd.itemid, "
    sqlstr &= "   im.stax, imd.prate / im.unitratio, imd.srate / im.unitratio, im.catcode, "
    sqlstr &= "  im.scatcode, MfgComTab.comname "
    sqlstr &= " Order By  im.iname ASC  "
    adapter.SelectCommand = New OleDb.OleDbCommand(sqlstr, con)

    adapter.SelectCommand.Parameters.AddWithValue("@date1", globals.fedate)
    adapter.SelectCommand.Parameters.AddWithValue("@date2", globals.fsdate)
    adapter.SelectCommand.Parameters.AddWithValue("@comcode", compcode)
    adapter.Fill(ds)
    dgvibatch.Refresh()



    If ds.Tables(0).Rows.Count > 0 Then


        dgvibatch.DataSource = ds.Tables(0).DefaultView
        dgvibatch.Columns("itemid").Visible = False
        dgvibatch.Columns("P Scheme").Visible = False
        dgvibatch.Columns("S Scheme").Visible = False
        dgvibatch.Columns("P Rate").Visible = False
        dgvibatch.Columns("units").Visible = False
        dgvibatch.Columns("Item").Width = 150
        dgvibatch.Columns("Rate").Width = 50
        dgvibatch.Columns("Tax").Width = 50
        dgvibatch.Columns("Stock").Width = 50
    Else
        ds.Dispose()

    End If
    con.Close()

0 个答案:

没有答案