开发者

Gridview with multiple tables?

Using C# and ASP.N开发者_运维问答ET, I need my gridview to draw columns from multiple tables. How do I do this? I currently have

`SelectCommand="SELECT [SubId], [CustName], [CustCity] FROM [Customer]">
    </asp:SqlDataSource>`

as my select statement, but I need to select from two more tables. What is the syntax?

apologies for being unclear before.


Your SelectCommand should be the same statement that you would execute if you were running the query on the database directly. So, in your case, you would want something like:

SELECT [SubId], [CustName], [BroName], [Entity] 
FROM [Customer] 
JOIN [Broker] ON <join condition> 
JOIN [Submission] ON <join condition>


If you don't need to update the SqlDataSource, you can simply put JOINS into your query.

For example:-

Select CustFld1, CustFld2, OrdFld1, OrdFld2 from Cust inner join Ord on CustPKeyFld=OrdCustFKeyField

If you do need to update the SqlDataSource, you need to use sub-queries to return the data that would otherwise be returned in the join

For example:-

Select CustFld1, CustFld2, (Select OrdFld1 from Ord where OrdCustFkeyFld=CustPKeyFld) as OrdFld1, (Select OrdFld2 from Ord where OrdCustFKeyFld=CustPKeyFld) as OrdFld2 from Cust

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜