Telerik - Winforms - Technique to save grid data to the database

There are two techniques that we use to save grid data to the database. One involves trapping the UserAddingRow, UserDeletingRow, and CellEndEdit events and committing the data to the database immediately.

That technique doesn't work or is not appropriate on all forms, like on a form that would have multiple changes going on at one time. An order entry form would have a total field that changed as the quantity in the grid was updated. In that case we hold all the changes and commit them with the Save button.

This article is a code example of that technique.

 

'commit to the database
For Each oRow As DataRow In Me.RadGridView1.DataSource.rows
    If oRow.RowState = DataRowState.Deleted Then
        intRowID = oRow("lRowID", DataRowVersion.Original)
    Else
        intRowID = oRow("lRowID")
        strItemNumber = oRow("vchrItemNumberGP")
        strUofM = oRow("vchrUnitOfMeasureGP")
        decQuantity = oRow("intQuantity")
        strBaseUofM = oRow("sBaseUofM")
        decBaseUofMQuantity = oRow("fltBaseUofMQuantity")
        decCalculatedQty = oRow("intCalculatedQty")
        decTaxAmount = oRow("curTaxAmount")
        strWarehouse = oRow("vchrLocationCodeGP")
        strItemLot = oRow("vchrLotnmbrGP")
        strNotes = oRow("txtItemNotes")
        decExtendedPrice = oRow("curExtendedPrice")
        bInactive = oRow("inactive")
        decGPPrice = oRow("curGPPrice")
        decItemPrice = oRow("curItemPrice")
        decItemPriceUofM = oRow("curItemPriceUofM")
    End If
    Select Case oRow.RowState
        Case DataRowState.Added
            DynData.SPs.FP_MasterOrderItems_INS(_UUID.ToString, strItemNumber, "",
                "", "", "", "", strUofM, strBaseUofM, decBaseUofMQuantity, decQuantity, decQuantity / decBaseUofMQuantity,
                Me.txtReqShipDate.Value, decGPPrice, decItemPrice,
                decItemPriceUofM, decExtendedPrice, decTaxAmount,
                strWarehouse, strItemLot, False,
                strNotes, appUser.UserName, appUser.Db).execute()
        Case DataRowState.Deleted
            DynData.SPs.FP_MasterOrderItems_DEL_byRowID(intRowID, 0, appUser.UserName, appUser.Db).execute()
        Case DataRowState.Modified
            Dim intRetVal As Int32 = DynData.SPs.FP_MasterOrderItems_UPD_byRowID2("", strUofM,
                strBaseUofM, decBaseUofMQuantity, decQuantity, decCalculatedQty,
                Me.txtReqShipDate.Value, decItemPrice, decItemPriceUofM,
                decExtendedPrice, decTaxAmount,
               strWarehouse, strItemLot, strNotes,
                intRowID, 0, appUser.UserName, bInactive, appUser.Db).execute
    End Select
Next
Me.RadGridView1.DataSource.AcceptChanges()

RealWorldCode gives developers practical, real‑world solutions with clean, working code — no fluff, no theory, just answers.
Links
Home
Knowledge Areas
Sitemap
Contact
Et cetera
Privacy Policy
Terms and Conditions
Cookie Preferences