Gridview and Select query
本文关键字:query Select and Gridview | 更新日期: 2023-09-27 18:13:42
我正在使用gridview和tables,我使用c#和asp.net。假设我有2个表,我们将其命名为Profiles和Info。
在表配置文件中,假设我有p_Id, FirstName, LastName字段,在Transaction中我有I_Id, childsID, fathersID, mothersID。
这是我的表的样子:
概要文件| p_Id | FirstName | LastName |
| 1 | Jack | Cole |
| 2 | Cynthia | Cole |
| 3 | Robert | Cole |
信息| I_Id | childsID | fathersID | mothersID |
| 1 | 1 | 3 | 2 |
现在在我的gridview中,我必须显示FirstName, LastName, Father和Mother。但是我需要显示他们的名字而不是他们的ID。
现在我的gridview是这样的:
First Name | Last Name | Father| Mother |
Jack | Cole | 3 | 2 |
我想要的是:
First Name | Last Name | Father | Mother |
Jack | Cole | Robert Cole | Cynthia Cole |
try this
select p.firstName, p.LastName
, (select sp.FirstName+' '+sp.Lastname FROM profile sp WHERE sp.p_id=i.fathersid) as father
, (select sp.FirstName+' '+sp.Lastname FROM profile sp WHERE sp.p_id=i.mothersid) as mother
from info i
inner join profile p ON (p.p_id=i.childsID)