开发者

About binding record to gridview from 2 tables in asp.net c#

I have one gridview. I have one table(source) that contains fields like sourceid, name and another table(target) that contains fields like targetid, from, to,date. In that target table from & to fields are ids refer to source table's sourceid's. So i have to bind record of target table i.e to bind fields : from - here name sh开发者_如何学Pythonould come respect to that source id from source table to - here name should come respect to that source id from source table date should come from target table.

How i can do this? Asp.net c#

Thank you.


You would want to perform a SQL inner join referencing the SourceTable twice -- once for the [From] column and once for [To] -- to output the columns you want into a single resultset.

SELECT t.targetid, t.[date], s1.[name] as [from], s2.[name] as [to]
FROM TargetTable t
INNER JOIN SourceTable s1
    ON t.from = s1.sourceid
INNER JOIN SourceTable s2
    ON t.to = s2.sourceid
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜