使用vb.net在Access DB中添加值/值之间的差异 [英] adding values/difference between values in Access DB using vb.net

查看:53
本文介绍了使用vb.net在Access DB中添加值/值之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我是vb.net的新手,正努力奋斗...我正在为自己的企业做一个小项目,而我在这两个星期前陷入了困境,但仍然没有进展.

我有一个具有以下列的访问数据库表"store" :( filldate,brand,model,plateno,mileage,litres),每次我公司中的汽车加油时,我都会在其中存储这些信息.例如:(8/25/2011,Renault,Megane,5487844,3943,20).

我现在想做的是在数据网格中显示两个日期之间的总汽油消耗量(公升)以及行驶的公里数(里程). (要有一份总消费的报告)

感谢任何帮助...谢谢你们!!!

Hello Guys,

I am new to vb.net trying to struggle ... 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. (to have a report with total consumption)

Any help appreciated ... Thank u guys !!

推荐答案

使用此查询:
Use this query:
SELECT SUM(Litres) AS TotalLitres, SUM(Mileage) AS TotalMileage
FROM Store
WHERE FillDate BETWEEN #MM/DD/YYYY# AND #MM/DD/YYYY#


将MM/DD/YYYY替换为实际日期.


Replace MM/DD/YYYY with actual dates.


我将使用以下功能:

I would use this function:

OleDbConnection con = new OleDbConnection(@"yourConString");
            OleDbCommand cmd = new OleDbCommand("SELECT MAX(Mileage) - MIN(Mileage), SUM(Litres) FROM Store WHERE PlateNo = @PlateNo AND Filldate BETWEEN @StartDate AND @EndDate",conEzstock);
            cmd.Parameters.AddWithValue("@PlateNo", 5487844);
            cmd.Parameters.AddWithValue("@StartDate", new DateTime(2011,8,1));
            cmd.Parameters.AddWithValue("@EndDate", new DateTime(2011,8,3));
            conEzstock.Open();
            OleDbDataReader dbr = cmd.ExecuteReader();
            int mileage;
            double litresUsed;
            while (dbr.Read())
            {
                mileage = (int)dbr[0];
                litresUsed = (double)dbr[1];
            }
            dbr.Close();
            con.Close();



希望对您有帮助



Hope this helps


这篇关于使用vb.net在Access DB中添加值/值之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆