简体   繁体   中英

C# SQL - Table Column Enumeration and JOIN

Good Evening SO Community!

I have a small Agenda C# program that uses a SQL Database. I am trying to fill a DataGridView, but I cannot achieve the thing I am trying to do:

For the current logged on user, I have 2 types of Datas I want to show in the grid view.

In the DataGridView, I would like to have the first column as "Tasks", which enumerates all the tasks a certain departement can perform (Given in another table), and the second column an editable TextBox for how long he did that certain task.

How my DataBase is built:

Tasks
- IdTask
- Nom
- IdDepartement

Departement
- IdDepartement
- Nom

Events
- IdEvents
- IdTask
- IdDepartement
- DuréeTache
- Date

Users
- IdUsers
- Nom
- IdDepartement
- IsAdmin

(I will modify those Table Columns the fit them under a single language. That is my bad.)

What I would like is something that looks like this, but with small modifications: MyDataGridView

I would love that all of the tasks, even those who has no Events related to them, appear and have 0:00:00 on the side since they have not been registered.

Currently, only registered events show up with their associated time.

I will also add a Save button at the bottom once the correct times have been entered.

So, I am looking for a SQL Select Query, that I do not know how to build. I have looked at Inner/Full Outer join, but they don't make appear all the tasks, even at 0:00:00.

If you need any clarifications, let me know!

Thanks for the help!


Edit #1: After adding a Cross Join, I obtained this: AfterModifications

It looks a lot more to what I want to achieve, but now I can see every departement's tasks, which is not good.

Here is my SQL Query: SELECT e.IdEvenement \\"#\\", t.Nom \\"Tâche\\", e.DuréeTache \\"Durée Tâche\\" FROM Evenements e LEFT OUTER JOIN Users u on u.IdUser = e.IdUser CROSS JOIN Taches t WHERE u.Nom = '" + this.Text + "' AND e.Date = '" + DTP_Date.Value.ToShortDateString() + "' this.Text would be the User's Name and DTP_Date is a DateTimePicker that only shows today's tasks.

Alright, so I tried stuff here and there, and finally came to a solution stop using a DataTable to bind to my DGV and instead manually make two separate queries to get the result I wanted. One to fill all my tasks for the given user, one to find the events related to those tasks/users combo.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM