c# - 带有 SQL 和 where 子句的 execute.scalar 始终返回 0
问题描述
当我尝试从 oracle db 读取一些记录时,我有一个奇怪的行为。我使用这段代码:
string sqlStatement = "select count(*) from EMP where code=1";
OleDbCommand chargeCount = new OleDbCommand(sqlStatement, conn);
if (chargeCount.Connection.State == ConnectionState.Open)
chargeCount.Connection.Close();
else
chargeCount.Connection.Open();
Console.WriteLine("No of records: {0}",
chargeCount.ExecuteScalar());
它总是返回 0,但应该返回 100000(正如我在 SQLplus 中使用上述 SQL 语句收到的那样)。
如果我将 sql 语句更改为“从 EMP 中选择 count(*)”,我会收到正确数量的记录。
看起来我在某个地方有错误。有人可以让我朝着正确的方向前进吗?
解决方案
推荐阅读
- postgresql - 获取具体化视图中的列列表
- amazon-ec2 - 为什么我的 SystemD 服务在重新启动时不重新启动?
- sql - Oracle SQL 在嵌套表中创建标识列
- c# - C#:使用语句和 this 关键字
- windows - 在没有 VC++/VS 的情况下调用 ActiveX COM 方法
- ionic-framework - 选择相机胶卷在 iOs 的 ionic/cordova 中不起作用没有任何反应
- excel - 如何在VBA中提取具有指定长度的单元格中的第一个数字实例?
- vba - 试图在 Microsoft Access 中为员工分配主管,查找是给我数字而不是名字?
- mysql - 使用spring boot的查询自定义问题
- kubernetes-helm - Helm 到 ConfigMap 以安装 fluentd 插件,并在 Jenkins 上收到此错误提示?