Create DBGrid columns at runtime with diffrent dataset (Table) - delphi

I want to create only certain columns on my "dbgrid" at run-time, and set them to
other table field(s) or same field . How do you do that :
illustration:
I have 3 Tables :
Student(IdStudent, NameStudent ...) ,
Module(idModul,NameModule...),
Notes(idNote,idStudent,idModul,Note).
I Want to insert All Notes in one Dbgrid and names of columns of DBgrid are names of Module Table. I have No idea?
Thanks.

You cannot do this with a dbgrid; dbgrids have only one datasource and a datasource has only one dataset. If you are using an SQL compliant database you should look into a join and/or crosstab to return a single dataset. (I think this is what MartynA is talking about) Or create a clientdataset at run-time and build it with the columns/data you want if you want data-aware. I would look into using a stringgrid, listview or treeview and build the whole thing by hand.

Related

How to join tables based on "Calculated Fields" in Tableau?

In order to join one of my tables to other tables, I had to use Calculated Fields to make the field format same as others. However, when I want to join the tables, the new field name created by Calculated Fields does not appear.
I know that I can export modified data, and import it again to solve the problem, but I'm interested to know if there is a simpler way to do so in Tableau.
Unfortunately you can not join in the data model using calculated field. If your data is not too large, you can make the join in Tableau by using data blending. Alternatively, create a view or views with the calculated field in the source SQL database.

How to show selected items of certain table on the different table in Dynamics AX 2012?

So, I have two tables InventTable (for inverntory) and MyCartTable. I want to connect this tables so when I chose some item or items in InventTable to show in MyCartTable's grid. MyCartTable fields are ItemNumber, ProductName, PartyID;
Assuming you are working with AX 2012:
On your MyCartTable, remove the itemNumber field.
Open an other AOT windows go to Data Dictionary - Extended Data Types and locate the itemId data type. Drag and drop this data type on your table. AX will ask if you want to add a foreign key relation. Click yes, this will add a relation to the InventTable to the relations node of your table.
Now on your form, set the JoinSource property of your MyCartTable to you inventTable data source.
If you are having trouble making this work, create a new form with only those two datasources and a minimum amount of controls (like just 2 grids), this allows you to test this more easily.

Tweaking a TDbGrid

I am taking my first stumbling steps into DB aware controls (any good tutorials?).
I have a MySql table with 6 columns and have managed to load it into a TDbGrid.
One of the columns however is an index into another table. It is a bar code and, rather than display that, I would like to display the product name associated with it.
How do I do that?
(and can I hide the "gutter" (?) down the left whcih shows the current row?)
Thanks
You should always perform a join from the SQL side, it's much easier then doing it programaticaly
Such as:
SELECT mytable.id, mytable.column1, another_table.barcode
FROM mytable
JOIN another_table ON another_table.id = mytable.barcode_id
To remove gutter you need to uncheck the DBGrid property dgIndicator in Options.
As for "DB-Aware controls" you should try delphi help.
Instead of a table, make use of a query. Then, use a join to select the product name with it, like this:
SELECT
t.*,
p.name
FROM
YourTable t
INNER JOIN Product p on p.barcode = t.barcode
I use t.*, because I don't know the exact columns. In practise, I would not use select *, but specify specific columns instead. If you are going to use * anyway, you can hide speicfic columns by setting the Visible property of the TField object in the dataset/query to False.
I don't know which components you are using to connect to the table, but most of them do have a query-counterpart that allows you to insert SQL instead of a table name.
The gutter can be hidden by going to the property Options in the object inspector, expand it, and set dgIndicator to False.
Just for the record: with ISAM databases like Paradox and DBF typical solution would be so-called master-detail tables relations and it still might work for SQL. Though it would be very inefficient and slow. You'd definitely read som books about SQL.
Use a TQuery component instead of a TTable and set SQL property using the suggested select statements above. If you just add the columns you want to display in your sql statement, you get the result as expected. As for "gutter" you would have to hack the grid in some way at runtime.

Delphi - TUpdateObject versus OnUpdateRecord for a join SQL statement

I have a pFibdataset(which is working similar to BDEDataset) in which I need to make the following join selection
select table.Name as name,
table1.Name as name_1,
table2.Name as name_2
from table
left join table table_1 on table.id=table_1.id
left join table table_2 on table.id=table_2.id
Fields name, name_1 and name_2 are linked to some data-aware edits. Now, I want after I'm modifying(update,delete,insert operations) the name,name_1 and name_2 fields to be updated in the tables. Based on the wiki Using_Multiple_Update_Objects_Index I can use UpdateObjects, or OnUpdateRecord event.
The problem is that I don't understand how this need to be implemented. I have the join select on the query, how I need to define and work with name_1 and name_2 fields. Can someone provide me an example for this?
I know how to use subqueries in order to accomplish this. I need to see how can I can make it by using UpdateObjects or OnUpdateRecord.
TpFibUpdateObject works like a trigger on client side. To make it work, set the following properties:
DataSet - dataset (master) to monitor
KindUpdate - Insert/Update/Delete - action to monitor
SQL - command to execute when action is fired, params are taken from DataSet
ExecuteOrder - AfterDefault/BeforeDefault - probably you need after / master
BUT, instead using a lot of UpdateObject components and such tangled approach, I recommend two alternative (read better) ways:
Updatable view. It will work like a "virtual table". Create a view that joins these theee tables and write Before Insert/Update/Delete triggers. In Delphi use it as a regular table: select from view / insert into view / update view and delete from view. Anyway I suppose you need in many places these tables linked toghether.
Use EXECUTE BLOCK statements in your TpFIBDataSet SQLs. Insert / Update / Delete in a batch all tables.
Solution : OnUpdateRecord it must be created an TUpdateObject for each field from the joined table.
UpdateObjectvariable.DataSet := Dataset;
fill the SQL text
Apply.
After all update objects are set, UpdateAction := uaApplied; must be called.

How to use MasterSource and MasterFields capability using FibPlus datasets or FibQuery

I am rewriting an existing BDE database program to use Firebird using the FibPlus components.
Since I almost every where used TQuery components, the change is fairly straightforward.
Apart from one thing I dont't seem to find :
In one of my forms I have two grids above each other, linked to TTable components, where the grid below only displays records with the same key as the selected record in the upper grid - so master/detail relationship.
This was done easy in BDE using the MasterSource and MasterFields properties.
How can this be achieved using the FibPlus FibDataset or FibQuery components ?
I don't think it's possible with a FibQuery, but with a FibDataSet there is a DataSource property which you should point to a DataSource connected to the master DataSet.
In the Detail fibDataSet a where clause shoudl be used where the parameter has the same name as the master field for the detail table in the master table.
For example:
master pFibDataSet CustomerspFibDataSet with the following SQL:
select cusotmerid, name, address, country from customers
A master DataSource CustomersDataSource with property DataSet set to CustomerpFibDataSet
detail pFibDataset OrderspFibDataSet with the property DataSource set to CustomersDataSource and the following SQL:
select orderid, date, amount from orders
where customerid = :customerid

Resources