Oracle資料庫“Specified cast is農田valid”

來源:互聯網
上載者:User

標籤:

 

這種錯誤是筆者在執行一條計算合格行有多少個,用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());

 

Oracle資料庫“Specified cast is農田valid”

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.