Reputation: 1379
Using C# and ASP.NET, 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.
Upvotes: 0
Views: 3745
Reputation: 1423
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>
Upvotes: 1
Reputation: 3025
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
Upvotes: 1