Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27192

VS 2008 DataGridView Update Problem

$
0
0
Good Evening All

I recently received some help on here from some of the guys in regards to updating a datagridview & saving the changes back to my database & they sorted the problem straight out.

However i have now come across another problem with the code which was working previously. I have added a section to the CellEndEdit code to automatically update & calculate one of the columns however now my update isnt working. Well it is however the last thing to change isnt being saved to the database.

Any ideas?

Code:

Private Sub dGridMaterials_CellEndEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dGridMaterials.CellEndEdit
        Dim intTotalMaterialCost As Decimal, intPurchaseCost As Decimal, intPurchaseSize As Decimal, strTotalCost As String = "0"
        For Each dGridRow As DataGridViewRow In dGridMaterials.Rows
            intPurchaseCost = dGridRow.Cells(7).Value
            intPurchaseSize = dGridRow.Cells(6).Value
            If intPurchaseCost <> 0 Or intPurchaseSize <> 0 Then
                intTotalMaterialCost = intPurchaseSize / intPurchaseCost
                dGridRow.Cells(8).Value = intTotalMaterialCost
            End If
        Next

        dGridMaterials.EndEdit()

        Dim sqlCommandBuilder As New SqlCommandBuilder(sqlDataAdapter)
        sqlDataAdapter.Update(sqlDataTable)
    End Sub

Many thanks in advanced

Frosty

Viewing all articles
Browse latest Browse all 27192

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>