user16384530
user16384530

Reputation:

How to join two tables into a asp.net gridview based on ID

this is my first time asking a question here.
I'm having a trouble with my gridview.
Here is the thing: I have a web application for check list and the user can have multiple projects and every project have it's own tasks.
What I'm trying to do is in the home page where I show the user his projects I want to grid view to show all projects and the number of tasks
The problem here is I have two tables: 1- tbl_projects, 2- tbl_tasks. The tasks table has foreign key connected with the project id in the projects table.

I tried to write this query in SqlDataSource, but it doesn't work.

Select tbl_projects.*, tbl_tasks.* from tbl_projects, tbl_tasks 
where tbl_projects.USER_ID = @USER_ID and tbl_projects.FAVORITE = @FAVORITE and tbl_tasks.PROJECT_ID = tbl_projects.PROJECT_ID

*And I'm sorry if my writing is bad

Upvotes: 0

Views: 626

Answers (1)

Serge
Serge

Reputation: 43860

try this

Select *   from tbl_projects
inner join tbl_tasks on tbl_tasks.PROJECT_ID = tbl_projects.PROJECT_ID
where tbl_projects.USER_ID = @USER_ID and tbl_projects.FAVORITE = @FAVORITE 

Upvotes: 1

Related Questions