首页 > 解决方案 > 带有 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(*)”,我会收到正确数量的记录。

看起来我在某个地方有错误。有人可以让我朝着正确的方向前进吗?

标签: c#oracle

解决方案


推荐阅读