VB.net 计算 Access 数据库中的行数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29474871/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 18:58:33  来源:igfitidea点击:

VB.net Count Rows in Access Database

vb.net

提问by override

I'm trying to count the enteries of my database where the users are 'employees'.
I have an Access DB with cName, cAge, cStatus

我正在尝试计算我的数据库中用户是“员工”的条目。
我有一个带有 cName、cAge、cStatus 的 Access DB

cStatus can either be 'Employee' or 'Customer'.

cStatus 可以是“员工”或“客户”。

I have no Idea how to get the Number of my 'Employees'.
Can anyone help?

我不知道如何获得我的“员工”数量。
任何人都可以帮忙吗?

回答by Luc

It would be a simple query. Since you didn't include details like table name or database name, I can only guess them:

这将是一个简单的查询。由于您没有包含表名或数据库名等详细信息,我只能猜测它们:

Dim con As OleDbConnection = Nothing
Dim cmd As OleDbCommand = Nothing
Dim numberOfEmployees as Int = 0;
con = New OleDbConnection()
con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=pathToDatabase"
con.Open()
cmd = New OleDbCommand("Select count(*) From tableToQuery where cStatus = \"Employee\"", con)
numberOfEmployees = cmd.ExecuteScalar()