VB.NET和Access DataBase趋势

时间:2022-09-15 18:30:05

This might be a simple question and answer but I am just stuck. =( Lets say we have a Access Database with items ordered by users saved

这可能是一个简单的问题和答案,但我只是卡住了。 =(假设我们有一个Access数据库,其中包含用户订购的项目

ID | Product Number | Product Name
-----------------------------------
1  | 00001          | Some Name 1
-----------------------------------
2  | 00001          | Some Name 1
-----------------------------------
3  | 00002          | Some Name 2
-----------------------------------
4  | 00003          | Some Name 3
-----------------------------------
5  | 00003          | Some Name 3
-----------------------------------

What I'd like is the code to

我想要的是代码

  • Open the db <-- Got that part down.
  • 打开数据库< - 得到那个部分。

  • Read the table with the said data listed above. <--Got this down

    阅读上面列出的上述数据表。 < - 得到了这个

  • Need Help : Report the most common Product number ordered.

    需要帮助:报告最常见的产品编号。

    I have messed with a few idea's but with no success. The data will be reported to a listview.

    我已经搞砸了一些想法,但没有成功。数据将报告给列表视图。

Thanks..

2 个解决方案

#1


0  

try this

Command.CommandText = "SELECT COUNT([Product Number]) AS CNT, [Product Number] FROM TableXXX GROUP BY [Product Number] ORDER BY COUNT([Product Number]) DESC"

#2


0  

You could just include most of this in your query to the database, like this (where t1 is your table name):

您可以在查询中将大部分内容包含在数据库中,如下所示(其中t1是您的表名):

SELECT [Product Number], count(*) as TotalOrders
FROM t1
GROUP BY [product number]
ORDER BY count(*) desc

That will automatically count and order the Product Numbers.

这将自动计算和订购产品编号。

#1


0  

try this

Command.CommandText = "SELECT COUNT([Product Number]) AS CNT, [Product Number] FROM TableXXX GROUP BY [Product Number] ORDER BY COUNT([Product Number]) DESC"

#2


0  

You could just include most of this in your query to the database, like this (where t1 is your table name):

您可以在查询中将大部分内容包含在数据库中,如下所示(其中t1是您的表名):

SELECT [Product Number], count(*) as TotalOrders
FROM t1
GROUP BY [product number]
ORDER BY count(*) desc

That will automatically count and order the Product Numbers.

这将自动计算和订购产品编号。