Right, this is probably going to be pretty simple. I have a form that contains a grid, if you select one of the records and press 'Edit' you get taken to another form where you can edit the data attached to that record - this all works.
However upon saving it will write it to the database but will not update the aforementioned grid until I come out of my program all together and then go back in.
All I want to do is get the grid to update when exiting the other form.
I have tried opening/closing the table components, calling the 'refresh' against the query and the table. I am connecting to the database using BDE and writing this in Rad Studio XE2.
Any help would be appreciated.
Hope this solves your problem
Table1.Active := False;
Table1.Active := True;
for a TTable and
TQuery1.Active := False;
TQuery1.active := True;
for a TQuery
Related
I have an Azure Data Factory Pipeline with a For Each Activity. This contains a Copy Data Activity which should insert into Azure Sql. I need to make use of the Additional columns feature but it refuses to let me select any value other than $$FILEPATH. It also will not let me type anything into the VALUE combo box.
Has anyone else hit this problem?
A workaround is to add a column as you did and change its value by editing the code of the pipeline.
The problem is a display issue with the scrolling menu hidden by a layer (I have it too). It is maybe specific to some web browsers.
I have a ListBox showing all the records for a single field (first) in a database. When users click the ListBox item I'd like the value for a different field in the db (last), same record, to be displayed. My code ListBox OnClick event code is:
SQLQuery2.SQL.Text:='SELECT * FROM Names WHERE first= :FIRST';
SQLQuery2.Params.ParamByName('FIRST').AsString := ListBox1.Items[ListBox1.ItemIndex];
SQLQuery2.Open;
ShowMessage('You selected '+SQLQuery2.FieldByName('last').AsString);
When you click an item, the expected field comes up in the MessageBox. However, if you then click a different item, nothing changes--the MessageBox shows the original field.
I don't know enough about SQLQuery components and how they interact with the underlying db to know what's happening.
[P.S. The db is sqlite3, if that matters, and I'm using Lazarus rather than Delphi, if that matters.]
You need to close your query before opening it again. If you look at the code for Open on TDataSet it sets the Active property to true. The setting code for Active first checks that the value is different before doing any work:
procedure TDataSet.SetActive(Value: Boolean);
begin
..
if Active <> Value then
begin
end;
end;
So in your case, the active property is already true and the code just exits.
I may have been too clever for my own good :-/
I have a table which holds some pressure measurements. These are always stored as PSI, but the user can select a radio group button to toggle between PSI and BAR.
In order to keep the code clean and and push work onto the database, I created a second table for configuration items, with a single row. One column psi_bar_conversion will take the value either 1 or 14.5 as the user toggles the radio group.
In Delphi, my query which ties to my DB grid is set up with statements like
SELECT ROUND(inlet_waterPressure_psi /
(SELECT psi_bar_conversion FROM configuration),
(SELECT float_precision FROM configuration))
AS inlet_waterPressure,
FROM measurements
All of which works just fine (and perhaps I am explaining too much).
All that I am tring to do is add some code in the function which handles the radio button toggle to force my DB grid to refresh its contents becuase I have just updated the value of configuration.psi_bar_conversion (but no direct field of my query, nor of my datasource).
Should I invoke Refresh() or Invalidate() or SomeOtherFunction() - of the DB grid, the query, the datasrouce? That's what is confusing me.
Thanks in advance for any help ....
You need to close and then reopen the query to have the change in psi_bar_conversion and float_precision to take effect. The two sub-selects (for the values from configuration) only happen when the query is executed.
TDBGrid presentation depends on the connected TDataSet (via a TDataSource).
To update the Grid Values you have to refresh the data in TDataSet with the method TDataSet.Refresh.
To update a special Grid you can refresh the connected DataSet like this:
DBGrid1.DataSource.DataSet.Refresh;
But some TDataSet descendants will not refresh and that is documented by Embarcadero
TDataSet.Refresh
It depends on the components you use (i did a test with UniDAC and it works fine)
procedure TForm1.RadioGroup1Click( Sender : TObject );
var
LRate : Extended;
begin
case RadioGroup1.ItemIndex of
0 :
LRate := 1;
1 :
LRate := 14.5;
end;
UniConnection1.ExecSQL( 'UPDATE configuration SET psi_bar_conversion = :conversion', [LRate] );
DBGrid1.DataSource.DataSet.Refresh;
end;
If your components did not refetch the data on calling Refresh, then you have to close and reopen (also stated by documentation)
DBGrid1.DataSource.DataSet.Close;
DBGrid1.DataSource.DataSet.Open;
IMHO such components are not fully implemented, so this is just a workaround having side effects in calling some maybe unwanted events (BeforeClose, AfterClose, BeforeOpen, AfterOpen) which will not get fired using Refresh.
But at all it has nothing to do with SubSelects.
I'm afarid I can't help you with the Delphi side of things here.
On the datbase side of things....
Is there any reason that you can't just store both the bar and psi values in the database?
You could do the conversion when saving and then you are left just to do a simple select on the data when you want to view it. This could be done by the software that is performing the save or by a trigger in the database.
The reason I suggest this is that the psi-bar conversion ratio is not going to change so you are doing a bunch of processing everytime you view the data that is not required...
My question may be quite stupid but I'm an absolute beginner, and I have a top urgent project to do.
I have created a WinForm app which works with a database containing several tables.
One of the tables is a users table which contains the following columns:
UserID - int, is identity = true| increment 1.
UserName - nvarchar.
Password - nvarchar.
VS2010 created a strongly typed Data set for me automatically, when I added the DB to my project.
I have created a form in which I have several text boxes. This form has a button that should update my dataset with information from several textboxes and than update the underlying database via the dataadapter.update() method.
Unfortunatly the data is never updated to the underlying database, I don't understand why and need your help. Thanks.
code sample (button click event):
LoginDataSetTableAdapters.LoginTableAdapter useraddadapter = new LoginDataSetTableAdapters.LoginTableAdapter();
LoginDataSet useraddset = new LoginDataSet();
LoginDataSet.LoginRow adduser = useraddset.Login.NewLoginRow();
adduser.UserName = textBoxUserName.Text;
adduser.Password = textBoxPassword.Text;
adduser.Email = textBoxEmail.Text;
adduser.Position = textBoxPosition.Text;
useraddset.Login.AddLoginRow(adduser);
useraddset.Tables[0].AcceptChanges();
useraddadapter.Update(useraddset.Login);
Calling the AcceptChanges method will commit all changes in the DataSet or DataTable. If it is called before the Update method is called, no changes will be committed when the Update method is called, unless further changes have been made since AcceptChanges or AcceptChanges was called.
Here is the scenario:
I have a winforms application using NHibernate. When launched, I populate a DataGridView with the results of a NHibernate query. This part works fine. If I update a record in that list and flush the session, the update takes in the database. Upon closing the form after the update, I call a method to retrieve a list of objects to populate the DataGridView again to pick up the change and also get any other changes that may have occurred by somebody else. The problem is that the record that got updated, NHibernate doesn't reflect the change in the list it gives me. When I insert or delete a record, everything works fine. It is just when I update, that I get this behavior. I narrowed it down to NHibernate with their caching mechanism. I cannot figure out a way to make NHibernate retrieve from the database instead of using the cache after an update occurs. I posted on the NHibernate forums, but the suggestions they gave me didn't work. I stated this and nobody replied back. I am not going to state what I have tried in case I didn't do it right. If you answer with something that I tried exactly, I will state it in the comments of your answer.
This is the code that I use to retrieve the list:
public IList<WorkOrder> FindBy(string fromDate, string toDate)
{
IQuery query = _currentSession.CreateQuery("from WorkOrder wo where wo.Date >= ? and wo.Date <= ?");
query.SetParameter(0, fromDate);
query.SetParameter(1, toDate);
return query.List<WorkOrder>();
}
The session is passed to the class when it is constructed. I can post my mapping file also, but I am not sure if there is anything wrong with it, since everything else works. Anybody seen this before? This is the first project that I have used NHibernate, thanks for the help.
After your update, Evict the object from the first level cache.
Session.Update(obj);
Session.Evict(obj);
You may want to commit and/or flush first.
what about refresh? - see 9.2. Loading an object of the docs:
"sess.Save(cat);
sess.Flush(); //force the SQL INSERT
sess.Refresh(cat); //re-read the state (after the trigger executes)
"