Problem with Array of Nullable types as parameter
Posted: Wed 25 May 2011 16:20
Hi all,
I want to call a stored procedure with an array parameter which actually works with not nullable types like decimal[].
I need NULL-Values in the Array so I decided to use decimal?[] instead of decimal[]. Now I get an InvalidCastException: Ungültige Umwandlung von "System.Decimal" in "System.Nullable`1[[System.Decimal, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]".
Any hints how I can solve this problem?
Thanks in advance,
Martin
I want to call a stored procedure with an array parameter which actually works with not nullable types like decimal[].
I need NULL-Values in the Array so I decided to use decimal?[] instead of decimal[]. Now I get an InvalidCastException: Ungültige Umwandlung von "System.Decimal" in "System.Nullable`1[[System.Decimal, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]".
Any hints how I can solve this problem?
Thanks in advance,
Martin
Code: Select all
OracleConnection conn = new OracleConnection("User Id=user;password=oracle;Direct=True; server=myserver;sid=mysid");
conn.Open();
decimal?[] numbers = new decimal?[] {1,2, null};
OracleCommand cmd = new OracleCommand("ptest.arrayparmtest", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("Result", OracleDbType.Number, ParameterDirection.ReturnValue);
cmd.Parameters.Add("numbers", OracleDbType.Double, numbers, ParameterDirection.Input);
cmd.ExecuteNonQuery();
decimal res = Convert.ToDecimal( cmd.Parameters["Result"].Value);
conn.Close();