locked
Unable to cast object of type 'Oracle.DataAccess.Types.OracleDecimal[]' to type 'System.Int32[]' RRS feed

  • Question

  • User-1986355015 posted

    notfound_numbers = (

    int[])cmd.Parameters["P_NOTFOUND"].Value

    causes error

    Unable to cast object of type 'Oracle.DataAccess.Types.OracleDecimal[]' to type 'System.Int32[]'

    With previous Oracle.DataAccess.dll (ODAC1020100)it works. What can I do(except returning to previous Oracle.DataAccess.dll)?

    Now I have ODAC112021.

    Wednesday, September 21, 2011 2:00 AM

Answers

  • User-1986355015 posted

    I rewrote the Oracle procedure so that it returns one value instead of array of values. And called it in a loop. So now programm works.

    But this is odd that ASP.NET code that worked with previous ODAC stops working with the next generation.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 4, 2011 1:55 AM

All replies

  • User269602965 posted

    use Oracle parameter OracleDataType,Decimal eventhough it is an interger and it will insert into an Oracle datatype NUMBER(x,0)

    Wednesday, September 21, 2011 12:55 PM
  • User-1986355015 posted

    It doesn't help.

    Below is the code.

    public static Dictionary<int, string> _Check_For_Reserve(int[] numbers)

    {

    int[] bad_numbers = new int[numbers.Length];

    int[] notfound_numbers = new int[numbers.Length];

    Dictionary<int, string> rez_numbers = new Dictionary<int, string>();

    try

    {

    string constr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

    OracleConnection conn = new OracleConnection(constr);

    conn.Open();

    if (System.Web.HttpContext.Current.User != null) { conn.ClientId = System.Web.HttpContext.Current.User.Identity.Name; }

    OracleCommand cmd = new OracleCommand();

    cmd.Connection = conn;

    cmd.CommandType =

    CommandType.StoredProcedure;

    cmd.CommandText =

    "arrayed_numbers.CHECK_FOR_RESERVE_NUMBERS";

    OracleParameter p_number = new OracleParameter();

    p_number.OracleDbType =

    OracleDbType.Int32;

    p_number.CollectionType =

    OracleCollectionType.PLSQLAssociativeArray;

    p_number.ParameterName =

    "P_NUMBER";

    p_number.Value = numbers;

    p_number.Size = numbers.Length;

    OracleParameter p_notfound = new OracleParameter();

    p_notfound.OracleDbType =

    OracleDbType.Decimal;

    //p_notfound.OracleDbType = OracleDbType.Int32;

    p_notfound.CollectionType =

    OracleCollectionType.PLSQLAssociativeArray;

    p_notfound.Value = notfound_numbers;

    p_notfound.ParameterName =

    "P_NOTFOUND";

    p_notfound.Size = notfound_numbers.Length;

    p_notfound.Direction =

    ParameterDirection.Output;

    cmd.Parameters.Add(p_number);

    OracleParameter p_bad_number = new OracleParameter();

    p_bad_number.OracleDbType =

    OracleDbType.Decimal;

    //p_bad_number.OracleDbType = OracleDbType.Int32;

    p_bad_number.CollectionType =

    OracleCollectionType.PLSQLAssociativeArray;

    p_bad_number.Value = bad_numbers;

    p_bad_number.Size = bad_numbers.Length;

    p_bad_number.ParameterName =

    "P_BAD_NUMBER";

    p_bad_number.Direction =

    ParameterDirection.Output;

    cmd.Parameters.Add(p_notfound);

    cmd.Parameters.Add(p_bad_number);

    cmd.ExecuteNonQuery();

    p_notfound.OracleDbType =

    OracleDbType.Decimal;

    notfound_numbers = (

    int[])cmd.Parameters["P_NOTFOUND"].Value;

    p_bad_number.OracleDbType =

    OracleDbType.Decimal;

    bad_numbers = (

    int[])cmd.Parameters["P_BAD_NUMBER"].Value;

    p_number.Dispose();

    p_notfound.Dispose();

    p_bad_number.Dispose();

    conn.Close();

    }

    catch (OracleException exc)

    {

    //char[] spl = new char[3] { 'O', 'R', 'A' };

    //string[] arr = exc.Message.Split(spl, StringSplitOptions.RemoveEmptyEntries);

    //return arr[0].Substring(arr[0].IndexOf(':') + 1);

    rez_numbers.Add(1, exc.Message);

    return rez_numbers;

    }

    int k = 0;

    for (int i = 0; i < numbers.Length; i++)

    {

    if (i < bad_numbers.Length)

    {

    if (bad_numbers[i] != 0)

    rez_numbers.Add(bad_numbers[i],

    " ");

    }

    if (i < notfound_numbers.Length)

    {

    if (notfound_numbers[i] != 0)

    rez_numbers.Add(notfound_numbers[i],

    " ");

    }

    else

    {

    if (!rez_numbers.ContainsKey(numbers[k]))

    rez_numbers.Add(numbers[k],

    "ok");

    k++;

    }

    }

    //if (result == -1)

    //{

    // return " " + bad_number.ToString() + " ";

    //}

    //else if (result == -2)

    //{

    // return " " + bad_number.ToString() + " ";

    //}

    return rez_numbers;

    }

    Wednesday, September 21, 2011 11:46 PM
  • User-1986355015 posted

    I rewrote the Oracle procedure so that it returns one value instead of array of values. And called it in a loop. So now programm works.

    But this is odd that ASP.NET code that worked with previous ODAC stops working with the next generation.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, October 4, 2011 1:55 AM