'Is There a way to update/refresh only one record in delphi dbgrid?
Is it possible? How?
Solution 1:[1]
If the TDBGrid was connected to a memory dataset you could. You would query the database for the selected record by ID, while modifying it (selected record) with the results (in-memory) you obtained.
Solution 2:[2]
What is your DataSet for the DataSource in DBGrid ?
If you are using ADOConnection, and working with ADOTable or ADOQuery as the DataSet, then you can try the following script :
ADOTable1.close;
ADOTable1.open;
or
ADOQuery1.close;
ADOQuery1.open;
Those scripts above will refresh the whole DBGrid.
As long as I know, there is now way to refresh one record in DBGrid. Correct me if I'm wrong. :)
Solution 3:[3]
You need to save the ID before refresh, and then you locate the same ID by positioning the cursor in the old Record. Like this:
procedure TForm1.refreshQuery;
var
oldID: integer;
begin
oldID :=query1Id_table.AsInteger;
query1.Refresh;
//or if refresh not works
//query1.close;
//query1.open;
query1.Locate('Id_table',oldID,[]);
end;
or depends of DataSet, see if this function works:
query1.RefreshCurrentRow;
Solution 4:[4]
You can use a input box asking something specific getting a value to look for the one you want to edit then you can use the locate function to find it and if it is found you edit and post
Var
sRegisterNo, sAnswer : string;
Begin
sAnswer := Inputbox('Registerno', 'Enter the user registerNo you want to edit' , '' );
With dmName do
Begin
sRegisterNo := tblMembers['RegisterNo'];
If sRegisterNo.locate(sAnswer, 'sRegisterNo') = True then
Begin
tblMembers.edit;
// Use edits to give the new values
// Ex. EdtRegisterno.text := RE001;
tblMembers.post
End;
End;
End;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | yozey |
Solution 2 | Galvion |
Solution 3 | |
Solution 4 |