Page 1 of 1

Using TCommand to update records. Changes not seen.

Posted: Tue 28 Nov 2006 19:05
by captainrproton
Hi,

I am writing an app that displays information about contractors currently on site. It is all working fine with one exception.

When a contractor comes on site their onsite status is change from "No" to "Yes". The statement I use is;

sqlstatement := 'UPDATE ' + suppliertable + ' SET OnSiteNow = ''' + onsitenow + ''' WHERE (EmployeeFirst=''' + firstname +
''' and EmployeeLast=''' + lastname + ''')';

employeeupdate.sql.Clear;
employeeupdate.sQL.add(sqlstatement);
employeeupdate.Execute();

The update is working because I can go into another application and see the change. In the app that made the change I can not see it. I destroy all controls and lists and stuff and do a full new query using tmyquery and the change is not there. If I exit the application and reload it is there.

I have tried this with autocommit on and off.

Are the changes cached somewhere, can I force them to be written. Why does this app not see the change, but I can load another program to look at the table and the changes are made. In this app I load another table, go back to this one and still no changes. I have to exit and reload the app for the changes to be seen.

Craig

Posted: Wed 29 Nov 2006 16:01
by Antaeus
Let's suppose that MyQuery is the dataset object that displays data from suppliertable. We can suggest the following ways to solve the problem:
1) Call Refresh or RefreshQuick method of MyQuery. Note, the RefreshQuick method requires a TIMESTAMP field in the table.
2) Scroll to the updated record in MyQuery and call the RefreshRecord method.
3) Make changes to suppliertable by Edit and Post methods of MyQuery instead of the UPDATE command execution with the employee object.

Posted: Wed 29 Nov 2006 19:18
by captainrproton
Thanks for the quick reply, I appreciate it very much.

I should have explained that I am not using a grid of any sort. I am getting each record individually and placing the results into a series of stringlists. I am doing it this way because I need to display many records in a way that is not possible with a standard dbgrid. Each record contains a photograph and I need to display all the photographs on my form side by side with other information about each employee below it.

I have tried the refresh and nothing happens. I have tried using both a tmycommand and a query component to update the database. Both perform the update, which I can verify with another application but it simply doesn't refresh in the main app.

Prior to getting all records, the stringlists and timage objects don't exist. I am creating them on the fly and filling them with information from the query 1 record at a time. When I am done there I destroy the stringlists and the image objects. If I then click the button to get records from the sql server it gets the records and recreates the stringlists and image objects.

I can't understand why the records the query gets aren't accurate. All other applications see the change, but not this one.

Refrest, update, post, none of it makes any difference. How do I find out what version of the SQL components I have. I purchased them well over a year ago, maybe there are some updates.

Posted: Wed 29 Nov 2006 23:12
by captainrproton
It is fixed. So don't worry about this problem.

For your info it wasn't a problem with your components, it was me - I AM AN IDIOT!

I was getting data from a tstringlist, which wasn't being freed and cleared therefore, each time records were added info was being appended to the stringlist. That meant that the first few entries never changed from their initital values.

I am sorry to have wasted your time. I am going outside to bang my head on a brick wall.

Craig

Posted: Thu 30 Nov 2006 08:51
by peter
"I am going outside to bang my head on a brick wall"

I thought you said it was your fault. Don't take it out on the wall :lol:




My informative TAGLINE follows:
CHECKOUT my experience with my lack of help from I-MATE in regards to my JASJAR at www.gizmoman.net/i-mate.htm