[英]Specified cast is not valid - exception
I have following situation. 我有以下情况。 I have PL/SQL - where I clicked "Describe" button on table and it told me type of one column is "INTEGER".
我有PL / SQL-单击表上的“描述”按钮,它告诉我一栏的类型是“ INTEGER”。 On the C# side I have this code to read that value:
在C#端,我有以下代码可读取该值:
// GET ID
if (!rdr.IsDBNull(rdr.GetOrdinal("ID")))
{
int ID = rdr.GetInt32(rdr.GetOrdinal("ID")); // Here I get exception
}
But I get this exception: 但是我得到这个异常:
Specified cast is not valid.
指定的演员表无效。
Can anyone help? 有人可以帮忙吗?
Stack trace: 堆栈跟踪:
StackTrace " at Oracle.DataAccess.Client.OracleDataReader.GetInt32(Int32 i)\\r\\n at GatewayFileImporter.Form1.button1_Click(Object sender, EventArgs e) in c:\\Users\\g\\Documents\\Visual Studio 2012\\Projects\\FileImpo\\FileImpo\\Form1.cs:line 86" string
位于c:\\ Users \\ g \\ Documents \\ Visual Studio 2012 \\ Projects \\ FileImpo中的GatewayFileImporter.Form1.button1_Click(Object sender,EventArgs e)处的Oracle.DataAccess.Client.OracleDataReader.GetInt32(Int32 i)\\ r \\ n \\ FileImpo \\ Form1.cs:第86行”字符串
From Oracle Data Type Mappings 从Oracle数据类型映射
This data type is an alias for the
NUMBER(38)
data type, and is designed so that theOracleDataReader
returns aSystem.Decimal
or OracleNumber instead of an integer value.此数据类型是
NUMBER(38)
数据类型的别名,其设计目的是使OracleDataReader
返回System.Decimal
或OracleNumber而不是整数值。 Using the .NET Framework data type can cause an overflow.使用.NET Framework数据类型可能会导致溢出。
Looks like this mapped to decimal in .NET side and you need to use GetDecimal
method instead; 看起来像这样映射到.NET端的十进制,您需要使用
GetDecimal
方法来代替;
decimal ID = rdr.GetDecimal(rdr.GetOrdinal("ID"));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.