1

I can't understand this. The code below always returns zero, even though when I run the same sql in sqlplus, I get the correct value. We just upgraded to Oracle 11g from 10g, and the code worked in 10g. What on earth could be going on?

_Sql = "SELECT Count(ObjectId) FROM AOR_MV_DEV WHERE CASE_NUMBER = 'S101-118'";
OracleCommand _Cmd = new OracleCommand(_Sql, _Cnxn);
_Cmd.CommandText = _Sql;
_reader = _Cmd.ExecuteReader();
_reader.Read();
vColumnValue = _reader.GetDecimal(0);
2
  • If I recall, the count() function in Oracle translates into a decimal (or maybe it was a double) value in .NET, not an integer - it shouldn't cause your problem, but have you tried debugging and calling _reader[0] to see what the true type returned is? Commented Jun 22, 2011 at 0:07
  • You are correct. I had Decimal originally, changed it to int to see if that might fix the issue, and forgot to change it back when I posted the code. I'll update the code. Thanks. Commented Jun 22, 2011 at 13:39

1 Answer 1

3

First, make sure you are using the right data provider for the version of .NET you are running on. That is the most likely culprit.

Other ideas:

Try using ExecuteScalar instead of executereader.

Try selecting 1 from dual: select 1 from dual. See if that returns 1. Then try select count(1) from dual and see if you get 1.

You don't need cmd.CommandText since you're already setting it when you create the command.

Also, you may need to qualify the table name with a schema name.

Sign up to request clarification or add additional context in comments.

1 Comment

If you'll update your answer to focus on the correct .Net library, I'll accept your answer. It seems Oracle 11g and .Net 3.5 System.Data.OracleClient don't play nicely together. I switched to Oracle.DataAccess.Client and that resolved the issue. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.