Forum > Databases

SqlQuery update status

(1/1)

Hansvb:
Hi,

The user can make changes in a table via a DbGrid. Now I only want to save if there are actually mutations. How can you check for that?
I thought of doing this with SqlQuery.UpdateStataus. But this only seems to be activated if you first go to a following line in the DbGrid. I want to see the UpdateStatus change as soon as I exit the cell. Is that possible?


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TFrm_Main.DBGridMain1ColExit(Sender: TObject);begin  case DataModuleMain.SQLQuery1.UpdateStatus of   usUnmodified :  Button2.Caption:='usUnmodified';   usModified :  Button2.Caption:='usModified';   usInserted :  Button2.Caption:='usInserted';   usDeleted :  Button2.Caption:='usDeleted';  end;end;  

Zvoni:
Why not use OnSelection-Event?
You need variables for oldValue, oldRow and oldCol where you save Row and Col when selecting a cell
OnSelection ships Col and Row of the newly selected Cell
Compare newValue to oldValue of Cell at "old" Col/Row, if "dirty" then update. Set oldCol/oldRow to current Col/Row, oldValue to current value

Hansvb:
Found something which i can use: Datasource.state. if a cell in DbGrid is changed the datasource state changes.

To see what happens when a cell changes:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TDataModuleMain.DataSource1StateChange(Sender: TObject);begin  case DataSource1.State of  dsInactive:    begin      ShowMessage('dsInactive');    end;  dsBrowse:    begin      ShowMessage('dsBrowse');    end;  dsEdit:    begin      ShowMessage('dsEdit');    end;  dsInsert:    begin      ShowMessage('dsInsert');    end;  dsCalcFields:    begin      ShowMessage('dsCalcFields');    end;  dsCurValue:    begin      ShowMessage('dsCurValue');    end;  dsNewValue:    begin      ShowMessage('dsNewValue');    end;  dsOldValue:    begin      ShowMessage('dsOldValue');    end;  dsFilter:    begin      ShowMessage('dsFilter');    end;  end;end;  

Navigation

[0] Message Index

Go to full version