Last post Sep 05, 2017 08:00 AM by Deepak Panchal
Sep 04, 2017 03:53 PM|LinaG|LINK
I'm using Visual Studio 2017 and SQL Server 2008 and I'm trying to display content form 2 tables (Topics and Catalogs - linked by a foreign key - each Topic has many catalogs). So, I tried with the bellow code but it doesn't understand "...WHERE Catalogs.id_Topic
var bd = Database.Open("IntranetConnectionString");
string query = "SELECT id, titleTopic FROM Topics";
var results = bd.Query(query);
foreach (var row in results)
string query1 = "SELECT titleCatalog FROM Catalogs WHERE Catalogs.id_Topic = @row.id ";
var results1 = bd.Query(query1);
foreach (var row1 in results1)
I want to display every catalogs for each topic. Is's possible what I pretend to do?
Thank you very much.
Sep 05, 2017 01:13 AM|Deepak Panchal|LINK
it will not work as you are trying in code above.
if you want to fetch data from more then one table then you need to use SQL Joins.
below is the example for joins.
Inner join :
SELECT title, pub_name
FROM titles INNER JOIN
publishers ON titles.pub_id = publishers.pub_id
FROM titles LEFT OUTER JOIN publishers
FROM titles RIGHT OUTER JOIN publishers
Full outer join:
FROM titles FULL OUTER JOIN publishers
so first you need to make a query with the use of joins and try to test it in SQL Server. once it working correctly then you can try to modify your code and use the query with in your code.
Sep 05, 2017 07:58 AM|LinaG|LINK
Ok. Thank you
Sep 05, 2017 08:00 AM|Deepak Panchal|LINK
if you think that the above suggestion can be the answer for your question then I suggest you to mark the answer.
it will help other community members in the future , who will have same kind of issue like yours.
Thanks for your understanding.