C#C
C#2y ago
Mek

✅ Trying To Get Better At Database Command Execution

code : https://pastebin.com/hH3nGTMe
how database is created: https://pastebin.com/wHLmbu9w

In my code above (link 1), I have a function and a model. The model is used to hold the totals that are going to be displayed on the home screen of my console based application. My goal is to get a much better understanding of sql commands with obtaining sums from items within a database. In link 2, is how the database is created. When I call the GetTotals() function from the home screen of my application, I want it to look like
Total Gas: $123,344
Total Mileage: 122,222
Total Maintenance: $123,123
just as an example. I know that there are sql commands that, when executed, can pull all the desired information from the table and sum up the numbers for me, however, I don't know how to do that. All I know to do is manually pull the information itself, pass that information off to a helper function, and sum the totals that way. Again, my goal here is to get better at the sql language and be able to write something like somethingHere.CommandText = @"SELECT x FROM table && SUM ALL x"; or however its written so that the sql execution does the summations for me and I can just write a one-line if statement to return the summation or 0 if no summation exists. Thanks in advance
Was this page helpful?