Question Calculate values in column and display in DataGridView

jadallah

New member
Joined
Aug 29, 2011
Messages
3
Programming Experience
Beginner
Hello Guys,

I am new to vb.net trying to struggle :dispirited: ... i am doing a small project for my business and i got stuck with this 2 weeks ago and still no progress.

I have an access db table "store" that has columns: (filldate,brand,model,plateno,mileage,litres) where i am storing these info each time a car in my company fills gas. For example (8/25/2011,Renault,Megane,5487844,3943,20).

What i want to do now is to display in a datagrid the total consumption of gas (litres) with the kilometers driven (mileage) between 2 dates.

Any help appreciated ... Thank u guys !!
 
My first question is why do you have the brand, model and plate number all in that table? What happens if you find the same plate number in two records with a different brand and model? You should have all that information in a different table and only the ID of that record in this table.

That aside, it's a simple matter of a query with an aggregate function:
VB.NET:
SELECT SUM(Mileage) AS Milage, SUM(Litres) AS Litres
FROM Store
WHERE FillDate >= @StartDate AND FillDate <= @EndDate
If you want it by vehicle then you can add a GROUP BY clause:
VB.NET:
SELECT PlateNo, SUM(Mileage) AS Milage, SUM(Litres) AS Litres
FROM Store
GROUP BY PlateNo
WHERE FillDate >= @StartDate AND FillDate <= @EndDate
 
Back
Top