Database Programming Techniques > Updating and Deleting the Current Record |
If the user finishes making changes to a cell, but stays in the same row, data is not updated to the database. You can force the row to be updated by applying the Update method of the grid. This method works for any DataMode setting:
TDBGrid1.Update
For a bound grid (ICursor) (DataMode property set to 0 - Bound), you can also force an update using the Update method of the Data control's Recordset:
Example Title |
Copy Code
|
---|---|
Data1.Recordset.Edit Data1.Recordset.Update |
Similarly, for a bound OLE DB grid (bound to an ADODC control):
Example Title |
Copy Code
|
---|---|
Adodc1.Recordset.Update |
And if bound to an ADO recordset directly:
Example Title |
Copy Code
|
---|---|
Recordset.Update |
You can delete the current row in any data mode using the grid's Delete method:
Example Title |
Copy Code
|
---|---|
TDBGrid1.Delete |
Note: When an OLE DB grid is bound to a data source for which batch updates are in effect (such as an ADO Recordset whose LockType property is set to adLockBatchOptimistic), the grid must not update the current record. In most cases, the grid can derive this information even though it is not part of the OLE DB specification. For the rare cases in which the grid cannot determine whether batch updates are in effect, you can set the BatchUpdates property in code to override the grid's default behavior.
To prevent updates from occurring when the user moves off a modified row, set BatchUpdates to True. To enable updates on a per-row basis, set BatchUpdates to False.