zoukankan      html  css  js  c++  java
  • Oracle数据库“Specified cast is农田valid”

    这种错误是笔者在执行一条计算符合条件的行有多少个,用OracleDataReader读取计算出的行数时发生。

    查询语句为:

    Select Count(1) FROM HP_TS  Where  TS_ID>0
    

     C#执行过程为:

    public static int GetSingle(string strSQL)
            {
                try
                {
                    OpenConnection();
                    OracleDataReader oraDataReader = ExecuteReader(Connection, CommandType.Text, strSQL, null);
                    int count = -1;
    if (oraDataReader.HasRows == true && oraDataReader.Read()) { count = oraDataReader.GetInt32(0); // ① 此处抛出该错误异常 }
    oraDataReader.Close(); return count; } catch (System.Exception ex) { throw ex; } }

    后来经过调试发现是由于oraDataReader[0] (或者是oraDataReader["Count(1)"]),的类型是decimal的,所以直接用以上代码①处的结果,将发生本文所述的异常。

    后来,给出如下解决方法:

    将①处替换为下面所示代码

    count = Convert.ToInt32(oraDataReader[0].ToString());
    
  • 相关阅读:
    UESTC
    Education Round 8 A
    Gym
    Gym
    hdoj 1159 Common Subsequence
    UVA
    UESTC
    51Nod 1068 Bash游戏 V3 (这规律不好找)
    51Nod 1066 Bash游戏
    51Nod 1002 数塔取数问题
  • 原文地址:https://www.cnblogs.com/arxive/p/5822668.html
Copyright © 2011-2022 走看看