delphi DBGrid显示JOIN结果
我正在使用 BDS 2006、MySQL DB(用于连接的 MyDAC 组件),并且我的表单上有一个 DBGrid 组件,它显示数据库表中的记录。
现在我需要JOIN
两个表并在我的DBGrid
中显示结果
我应该得到的结果视图是查询
SELECT e_salary.e_basic,e_details 的结果.e_name 来自电子详细信息 内连接 e_salary ON e_details.e_id=e_salary.e_id;
时,还有一个选项可以做到这一点
当我搜索SELECT e_salary.e_basic,e_details.e_name 从 电子详细信息、电子工资 在哪里 e_details.e_id=e_salary.e_id;
e_details,e_salary 是我的两个表,e_id 是我的主键
目前我有 2 个 DBGrid
一个用于 e_details, e_salary 的其他
是否可以只有 1 个 DBGrid 显示两个表中的值?或者我必须显示 2 个单独的 DBGrid?
如果可能的话,我该怎么做
P.S.-视图中需要添加更多列,并且两个表的行数相同
提前致谢
I am working with BDS 2006,MySQL DB (MyDAC components used for connection) and i have a DBGrid
component on my form which displays the records from my DB table.
Now i need to JOIN
two tables and display the results in my DBGrid
The Resulting view that I should get is the result of the query
SELECT e_salary.e_basic,e_details.e_name
FROM e_details
INNER JOIN e_salary
ON e_details.e_id=e_salary.e_id;
there is one more option to do it as I searched
SELECT
e_salary.e_basic,e_details.e_name
FROM
e_details, e_salary
WHERE
e_details.e_id=e_salary.e_id;
e_details,e_salary are my two tables and e_id is my PRIMARY KEY
Presently I am having 2 DBGrid
one is for e_details and other for e_salary
Is it possible to have only 1 DBGrid displaying values from both the Tables? or I have to display 2 separate DBGrid
?
If possible then how do I go about it
P.S.- there are more columns to be added in the view and both tables have same no of rows
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
DBGrid
显示数据集数据。数据可能是某些 SQL 查询执行的结果。DBGrid
、TDataSet
和TDataSource
不关心 SQL 查询是什么。单表SELECT
、带有联接、存储过程调用或SHOW
命令的多表SELECT
。所以,是的 - 您可以使用 1 个 DBGrid 来显示连接 2 个表的SELECT
结果集。e_id
是两个表的主键,那么为什么不使用单个表来包含两个表的列呢?此外,如果您需要编辑数据集数据,则更新两个表的列可能会出现问题。这可能是使用单个表的又一个论据。WHERE e_details.e_id=e_salary.e_id
而不是JOIN e_salary ON e_details.e_id=e_salary.e_id
。 JOIN 是首选,因为 DBMS 更明确地了解您的意图,并且对其他人来说更具可读性。DBGrid
displays a dataset data. The data may be result of some SQL query execution.DBGrid
,TDataSet
andTDataSource
do not cary what was the SQL query. Single tableSELECT
, multi tableSELECT
with joins, stored procedure call orSHOW
command. So, yes - you can use 1 DBGrid to display resultset of yourSELECT
joining 2 tables.e_id
is primary key for both tables, then why not to have single table, containing columns of both tables ? Also, if you will need to edit your dataset data, then there may be problems to update columns of both tables. And that may be one more argument to have single table.WHERE e_details.e_id=e_salary.e_id
instead ofJOIN e_salary ON e_details.e_id=e_salary.e_id
. The JOIN is preferred, because DBMS gets your intent more explicitly and that is more readable for others.DBgrid 可能不是您需要的组件。
关注 TTreeView
http://delphi.about.com/od/vclusing /l/aa060603a.htm
The DBgrid is probably not the component you need.
Give an eye to the TTreeView
http://delphi.about.com/od/vclusing/l/aa060603a.htm