how to connect dbgrid with adoquery with paramaters - delphi

I'm trying to use Adoquery with parameter (start day and end day ) in delphi 7 but the problem is when i click button filter (with suppose to filter the dbgrid using sdateedit1.date and sdateedit2.date) i got an empty rows , Please help me
I try to check the adoquery if it's enable or not
I try to check the connection string , and the sql query is correct
and i try to checked the dbgrid datasource is using the right adoquery

Related

DbLookUpComboBox Dropdown

enter image description hereDbLookUpComboBox Not Working
Im starting a School project and very new in Delphi
I created a form with ADO, ADO connection and ADOQuery controls
I Added the DbLookUpComboBox control to the form
I also setup everything as explained through other guides.
When I run the program, the Combo Box get populated, and I can see all Items from the Access Database.
My Problem is it wont Allow me to select any of the listed Items.
Almost like the Items is disabled in the list
Is there anything Im doing wrong or need to enable to allow me to select items from the combo box
I managed to get the dblookupCombobox to work selecting items using the up and down arrow keys . I s\cant select items using the mouse
I actually figured it out eventually.
I only had to add another ADOQuery and Source.
Then Swop the List field key and datafield around

Date format does not display correctly until app is closed and reopened

I am working on a simple database application in Delphi using FireDAC and SQLite3. Whenever I insert a new record into the database, the date format that is shown on my form is always in the format of yyyy-mm-dd and once I close and reopen the application the format changes to m/d/yyyy which is the format I was expecting and wish to always be displayed without closing and reopening my application.
The Definition Parameters and Options for the FireDAC connection are all at their default values. The DataType set for the field that holds the date in the SQLite3 database is set to DATE. Finally, the code I use to insert the record is below.
Qry.SQL.Text := 'INSERT INTO employees (HireDate) VALUES (:HiredOn)';
Qry.ParamByName('HiredOn').AsDate := DateTimePicker1.Date;
Qry.ExecSQL;
Qry.Open('SELECT * FROM employees');
Any help would be appreciated.
Make sure that any format settings for the date field in the underlying BindingSource / List / Adapter matches that of the form/grid field. It might be that the underlying binding formatting for the field is overriding your new settings for the form/grid field.
Set the format/display on your form field to "m/d/yyyy" and for good measure, *also do it through code in the InitializeGrid event handler
This is happening b/c when the date format on your form field doesn't match that in SQLite3 which is "yyyy-mm-dd". So you would need to set the format/display on your form field to match that.
Uses DateUtils ...
DateUtils.DateOf(DateTimePicker1.Date);
Try
FormatDateTime('dd/mm/yyyy', DateTimePicker1.Date);

Firedac Query Field list not updated after Schema change

I am creating a temp table in SQL and then adding a new field to it. It seems Firedac is caching the field list for this temp table.
The following code gives me "FDQuery5: Field 'Available' not found."
FDQuery5.Connection := FDConnection1;
FDConnection1.ExecSQL('Select StockNo into #Temp from Stock');
FDQuery5.SQL.Text := 'Select * From #Temp';
FDQuery5.open;
FDConnection1.ExecSQL('Alter Table #Temp add Available Char(1)');
FDQuery5.Close;
FDQuery5.open;
ShowMessage(FDQuery5.FieldByName('Available').AsString);
using XE5 with Firedac.
I have tried Connection.RefreshMetadataCache and I have removed fiMeta from FetchOptions.Cache.
I can get Firedac to recognise the new field if I modify the SQL.Text. This is undesirable as my application will need modifying in quite a few places.
The query remains prepared after you call FDQuery5.Close. That means, it caches also result set structure. To prepare the query replace FDQuery5.Close with FDQuery5.Disconnect.

Missing Field Errors In TClientDataSet when external dll called from Delphi 7

I have a DLL created in Delphi XE2 that is using DB Express and TClientDataSet to display the results of a join in a DB Grid. There is a simple function to launch/show the form that is exported for use in other applications. The query is executed, and the grid populated, on FormActivate.
When I call the function to show the form from a separate Delphi XE2 application, everything runs fine - no issues that I can find.
However, when I call the same function from a separate Delphi 7 application, I get an error that that TClientDataSet can't find fields from the join.
For Example, data is returned like this:
[dbxds == TSQLDataSet
cds == TClientDataSet]
dbxds.commandtext='select s.sfield1, s.sfield2, t.tfield1, t.tfield2 from s left join t on s.sfield1 = t.tfield1';
cds.Open;
cds.fieldByName(sfield2).visible:=false;//to hide from a dbgrid
cds.fieldByName(tfield2).visible:=false;//to hide from a dbgrid
When called from XE2, no issues.
When called from Delphi 7, the last line (used to hide that field from the db grid) gives an error that:
cds: Field 'tfield2' not found
Though the first line is fine - if I switch the order of the query so that that 't' fields are retrieved first ('from t left join s'), then I get the error on the 's' field instead.
Any thoughts on what could be causing the incompatibility?
Thanks!
OK so, I noticed something odd and that put me on the path to getting the answer to this.
It just happened that, in either table, the field I was trying to access to hide was of type 'tinyint(1)'. If I tried to hide a field of type int/varchar etc, no error was thrown.
I swapped my 'tinyint(1)' fields for 'int(1)' and it works fine.
No idea why this was happening, but I'm glad I caught it and, if any one else runs into this issue, I hope that this answers their question for them too.

Fastreport and TSQLQuery

I use TSQLQuery (from DBExpress) to run a query on two Mysql Tables. Now i want to print a report from that Query using FastReport but i don't know how to do it!
Help me please.
If you enable the query at runtime (fill in relevant params if need be in the designer), you can doubleclick the TSQLQuery to bring up the field designer.
Choose add all fields.
Now you can add a datasource to that TSQLQuery and link the fields to your FastReport.
I strongly advise you to connect the query to the default SQLConnection at design time, and not at run-time, as you are currently doing (according to your comment). This will enable you to see the fields of the query and so link the correct fields to the FastReport.

Resources