0

我正在使用 gridview 和表格,我正在使用 c# 和 asp.net。假设我有 2 个表,让我们将其命名为 Profiles 和 Info。

在表配置文件中,假设我有带有 p_Id、FirstName、LastName 的字段,而在事务中我有 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         |

现在在我的网格视图中,我必须显示名字、姓氏、父亲和母亲。但我需要显示他们的名字而不是他们的 ID。

现在我的gridview看起来像这样:

First Name | Last Name | Father| Mother |

Jack       | Cole      | 3     | 2      |

我想要的是这样的:

First Name | Last Name | Father      | Mother       |

Jack       | Cole      | Robert Cole | Cynthia Cole |
4

1 回答 1

1

试试这个

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)
于 2013-05-16T04:20:05.343 回答