Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change data in DBGrid

Status
Not open for further replies.

lespaul

Programmer
Feb 4, 2002
7,083
US
I have a query that is the source for a dataset which is the source for my DBGrid. When the user doubleclicks on a record I'd like to modify a field in my table (change the status code from NR to RU). First is this possible? Second, do I need to put the dataset.state to edit or is it already in that state? Third, do I need a new update query or can I just change the value in the dataset and have it update the table?

Thanks for any assistance
Leslie
landrews@metrocourt.state.nm.us

SELECT * FROM USERS WHERE CLUE > 0
No Rows Returned
 
Leslie,

Depending on the database format you're working with, your best bet may be to create a separate dialog box that appears when the user double-clicks your grid. Populate this with the objects appropriate for your record and then add an Update button that runs an UPDATE query when clicked.

There are, of course, other ways to do this, depending on the database format you're working with and the features it supports. For example, the Paradox file format allows (if you're using BDE) updateable views, meaning it's possible to create select queries that can directly update the dataset. There are a number of conditions associated with these, but if you can make them work in this instance, they can be very powerful.

If you're using TClientDatasets to connect to your data, then there are certain features, such as cached updated and so on, that may be very useful. For more information, see the Help file topic group called "Overview of cached updates."

Of course, this ties your code to a specific implementation. If there's any chance you might change the database at some point in the future, then you're best bet is to use a general UPDATE query. YMMV.

Hope this helps...

-- Lance
 
Thanks Lance, actually my problem was that I was referencing the dataset when I really needed to be using the query.

procedure TfrmJurorSearch.DBGSearchResultDblClick(Sender: TObject);
begin
With JMSData.qryJurorSearch do
begin
Edit;
FieldValues['STATUSCD'] := 'RU';
Post;
end;

end;

Leslie
landrews@metrocourt.state.nm.us

SELECT * FROM USERS WHERE CLUE > 0
No Rows Returned
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top