I was tasked with writing a winforms C # application that allows users to run special requests. I searched the Internet and found many tools that you can buy ( EasyQuery ), but this time the purchase is out of the question.
So I'm trying to write it myself. At this point, I created a tree view that is populated with tables / columns at runtime, and I can select the columns that users checked. But now I have to figure out how to dynamically JOIN tables they selected.
The structure of the partial table below:
Table - Roles - PK = RoleId RoleId RoleName Table - Center PK = CenterId/RoleId/Prefix CenterId RoleId Prefix Table - Employee - PK = EmployeeID EmployeeId Name CenterId Dept Org Table - Prof - PK = EmployeeId/Profile EmployeeId Profile
I have a total of 6 tables that can be combined into different fields, but since users need to join on the fly, I need to define a JOIN when they want to generate SQL. At the moment, I donโt know how best to start generating these JOINs .
I even thought about creating a table in the database with the JOINs specified for each table / column, and then I could just build it there, but I'm at a loss.
I also tried something similar, but I do not want to start from the wrong path, if there are suggestions in a different way:
private void GetJoins() { string joinList = string.Empty; foreach (TreeNode tn in TablesTreeView.Nodes) { if (tn.Checked) if (tn.Nodes.Count > 0)
It seems like this is on the right track or can you suggest another way?
I know that this will be an incredibly difficult task, and I have not yet reached the dynamic WHERE . I'm just looking for advice on the best way to create JOINs on a one-time basis.