I have a database (table) on Microsoft Access that's constantly updating from python and I have a form displaying Fields from that table. How do I make a form update (refresh) automatically when data is added to the table it's reading from?
I've set a button that runs Me.Requery when pressed thus refreshing the Form and getting the new data, but I want for to update/refresh automatically. On Data change (Form_datachange) doesn't work (don't know why).
I don’t think you can run a macro to requery your form when the table updates due to the restrictions on data macros.
However, you can put your requery logic in the form’s OnTimer event and set it to run at a desired interval (e.g. 5000 ms which is 5 seconds)
Related
I use QSqlRelationalTableModel to extract data from database, and use tableView to show it. Now, when I update my database, how to update tableView automatically to show it? I know i need to use function dataChanged() to make this automatically, but i do not know how to use it? Any suggestion will be appreciated.
The main code is as follows:
QSqlRelationalTableModel *model = new QSqlRelationalTableModel(NULL, db);
model->setTable(tableName);
model->select();
tableView->setModel(model);
tableView->show();
No, there is no need to use dataChanged().
You just need to call QSqlRelationalTableModel::select() whenever the database gets updated. This will re-populate the model from the database, and update the views that are using it automatically.
If the database is updated from within you application, you can just call model->select() after the update queries get executed in your application.
If the database is updated from another application, you'll have to use something like PostgreSQL's event notification system, subscribe to the notification from your application using QSqlDriver::subscribeToNotification() and call model->select() in a slot connected to the notification() signal.
You can use QSqlDriver::hasFeature(QSqlDriver::EventNotifications) to check if notifications from your database are supported.
I am developing a web app using Oracle ADF. I have a bounded task flow. In that I have a search page like below.
I have created the above two forms using view object data controls.
Searching is performing well. But my problem is when I go some where else in my application using menus provided left side and come back to the search page , the page is not getting refreshed. I am getting a search page that contains old search results. At this point of time if I am trying to make any changes am getting some error called "Another user with this id already modifed data ....". After this error my app is not running. Means what ever am trying to do its showing the same error.
So I need to make this: "When ever the user come to this form, He should get fresh form. It should not contain old search results.
Please help me. How do I achieve this.
Thank you.
There are 2 ways of doing it:
1) Set your task flow as ISOLATED, from Task Flow Overview tab -> Behaviour -> Share Data Control with calling task flow -> unchecked (or isolated, if you are using JDev 12c)
This will ensure you always start FRESH when accessing the page, but it will potentially create a performance overhead because entire View Object cache will be recreated (requeried) on page load. Nevertheless, it is the quickest solution.
2) You may create a default Method Call Activity in your task flow from where you may call a AM's custom method that resets the view criteria. The method will be placed on application module's implementation class and it may look like this:
public void initTaskFlow() {
this.getViewObject1().executeEmptyRowSet();
}
This will clean the result data. If you want to reset the querying parameters as well, you can use this example:
http://www.jobinesh.com/2011/04/programmatically-resetting-and-search.html
When you made any changes to any viewObject then excute this viewObject to match entity state and viewState , i think excuting viewObject will solve your issue
Ashish
I have a simple TClientDataSet component that I use to populate some data-aware components. However, if I insert data into my database using this dataset, I can't seem to find a proper way to sync it back into my TClientDataSet component.
How do I achieve this?
The TClientDataSet component has a Refresh method that does exactly that. Took some time for me to find this out in the docs, though. :)
From the docs:
From DB.pas
procedure Refresh;
Re-fetches data from the database to update a dataset's view of data.
Call Refresh to ensure that an application has the latest data from a database. For example, when an application turns off filtering for a dataset, it should immediately call Refresh to display all records in the dataset, not just those that used to meet the filter condition.
Note: The Refresh method does not work for all TDataSet descendants. In particular, TQuery components do not support the Refresh method if the query is not "live". To refresh a static TQuery, close and reopen the dataset.
TDataSet generates a BeforeRefresh event before refreshing the records and an AfterRefresh event afterwards.
Note: Most datasets try to maintain the current record position when you call refresh. However, this is not always possible. For example, the current record may have been deleted from the server by another user. Unidirectional datasets have no mechanism for locating the current record after a refresh, and always move back to the first record.
Warning: Unidirectional datasets refresh the data by closing and reopening the cursor. This can have unintended side effects if, for example, you have code in the BeforeClose, AfterClose, BeforeOpen, or AfterOpen event handlers.
Closing and opening the CDS didn't work for me. I'm using Delphi XE2, Update 3, with ADO tables connecting to an Access 2007 database. The only way I could refresh the data in my CDS was this:
procedure TForm1.PeopleRefreshButtonClick(Sender: TObject);
// this actually re-loads the data from the table!
begin
DM1.PeopleTable.Close;
DM1.PeopleTable.Open;
DM1.PeopleCDS.Refresh;
end;
A refresh button on the form closes, then opens the table. Then I refresh the ClientDataSet.
Basically, you must close the TClientDataset and then open it, loading the data from the database the same way you did originally. If the TClientDataset is connected to a TDataSetProvider, which is connected to a TDataset/TQuery descendant, all you have to do is close TClientDataset then open it.
I'm trying to figure out a user friendly way to pass messages to users from my Apex code. I have a trigger which fires after insert/update of a lead, which then filters the list of updates and triggers a #future method which pushes the lead data out to an external web service and updates the converted account with some of the returned values.
I'd like to do the following (where X, Y and Z are any number of leads from 1 to 50)
notify the user converting the leads that leads X, Y and Z will be exported (I'll know this during the trigger execution).
notify the user whether the export succeeded or failed (which will be known for each of X, Y and Z when the #future method runs).
What is the recommended way to pass this information back to the user? I'd prefer not to use email (as this would trigger one email per record, which is pretty spammy and unpleasant). Is there another way to inject notification messages into a page? I've tried ApexPages.addMessage() but it doesn't seem to do anything for me (no error, but no notice either).
addMessage() works with both Visualforce pages and standard pages when there's a current page active, so using this in the trigger should work fine if the user is firing the action from a button / VF page. Using this won't work from your #future method however because it runs asynchronously in the background.
Maybe the best solution would be to use a custom message object, which has a list of fields modified, when, and has a lookup to the appropriate user (or uses them as the owner). You could then create a simple VF page and controller which when viewed queries for records in that object related to the current user and provides an option to delete them (you could automatically delete them after pulling them from the DB but you run the risk of the user not actually noticing a message). You can then take this page and use it as part of a dashboard component, so anytime the user is viewing their Home page they could see a list of notifications.
Finally another option might be making use of Chatter, pumping the messages to the user via that which will then also show up in digest emails etc..
I am planning to have a (Telerik MVC) grid in which each row has a button. On click, a boolean will be updated in the DB via ajax and the callback function will set a "checkmark" image in one of the row's cells. The user should be able to click on multiple rows in rapid-fire fashion, and I'm trying to anticipate any problems if he does so. Is there a possibility of contention either in the DOM or in the database server?
To make sure that user experience does not suffer, here's what I'd do:
Create an array of objects to be update
Every time an checkbox is clicked, add/update it to/in the array with the value - this will make sure that multiple clicks to the same checkbox will result in only one AJAX call
After adding a check box to array, start the AJAX update process
On AJAX response, check if there are any items in the array to be processed and repeat
The biggest factor will probably be how quickly your server handles the Ajax request. If it takes a while, then the user experience will suck.
You could possibly make this better by adding the keys to a variable, and just sending to the server periodically, eg:
User clicks an item
Add key to array
Use window.setTimeout() to kick off the send function in x milliseconds
User clicks another item
Add key to array
Timeout already set, so doesn't do anything more
Timeout expires, code runs, sends both keys to server in one request
User clicks an item
Add key to array
Use window.setTimeout() to kick off the send function in x milliseconds
etc.