Oracle参数不受支持

时间:2012-03-15 17:04:37

标签: c# oracle devart dotconnect

我得到这个错误的消息:

System.ArgumentException未处理   Message =不支持类型Devart.Data.Oracle.OracleParameter的值。

...使用此代码:

    OracleParameter pRes = new OracleParameter("C_REF", OracleDbType.Cursor);
    pRes.Direction = ParameterDirection.ReturnValue;

    oracleCommand1.Parameters.Clear();
    int iFromYear = dateTimePickerFrom.Value.Year;
    int iFromMonth = dateTimePickerFrom.Value.Month;
    int iFromDay = dateTimePickerFrom.Value.Day;
    int iToYear = dateTimePickerTo.Value.Year;
    int iToMonth = dateTimePickerTo.Value.Month;
    int iToDay = dateTimePickerTo.Value.Day;
    oracleCommand1.Parameters.Add("iStartDate", new DateTime(iFromYear, iFromMonth, iFromDay));
    oracleCommand1.Parameters.Add("iEndDate", new DateTime(iToYear, iToMonth, iToDay));
    oracleCommand1.Parameters.Add("iCATEGORYID", 114);
    oracleCommand1.Parameters.Add("c_ref", pRes);
    oracleConnection1.Open();
    oracleCommand1.ExecuteCursor(); 

更新以回应评论:

那么可以用什么代替OracleParameter来传递?

当我把它变成这个时(我只是像一只饥饿的鸡一样四处乱窜):

    oracleConnection1.Open();
    OracleDataReader myReader = oracleCommand1.ExecuteReader();
    OracleParameter pRes = new OracleParameter("C_REF", myReader);
    pRes.Direction = ParameterDirection.InputOutput; // <-- devArt's code

    oracleCommand1.Parameters.Clear();
    int iFromYear = dateTimePickerFrom.Value.Year;
    int iFromMonth = dateTimePickerFrom.Value.Month;
    int iFromDay = dateTimePickerFrom.Value.Day;
    int iToYear = dateTimePickerTo.Value.Year;
    int iToMonth = dateTimePickerTo.Value.Month;
    int iToDay = dateTimePickerTo.Value.Day;
    oracleCommand1.Parameters.Add("iStartDate", new DateTime(iFromYear, iFromMonth, iFromDay));
    oracleCommand1.Parameters.Add("iEndDate", new DateTime(iToYear, iToMonth, iToDay));
    oracleCommand1.Parameters.Add("iCATEGORYID", 114);
    oracleCommand1.Parameters.Add("c_ref", pRes);
    while (myReader.Read())
    {
        ;// Console.WriteLine(myReader.GetInt32(0) + ", " + myReader.GetString(myReader.GetOrdinal("DName")));
    }
    // always call Close when done reading. 
    myReader.Close();

......我得到的也不错,但我也没有数据。

更新到更新:

好的,我终于明白了。这些可能并不优雅,但它确实可以追溯数据:

    oracleCommand1.Parameters.Clear();
    int iFromYear = dateTimePickerFrom.Value.Year;
    int iFromMonth = dateTimePickerFrom.Value.Month;
    int iFromDay = dateTimePickerFrom.Value.Day;
    int iToYear = dateTimePickerTo.Value.Year;
    int iToMonth = dateTimePickerTo.Value.Month;
    int iToDay = dateTimePickerTo.Value.Day;
    oracleCommand1.Parameters.Add("iStartDate", new DateTime(iFromYear, iFromMonth, iFromDay));
    oracleCommand1.Parameters.Add("iEndDate", new DateTime(iToYear, iToMonth, iToDay));
    oracleCommand1.Parameters.Add("iCATEGORYID", 114);

    oracleConnection1.Open();
    OracleDataReader myReader = oracleCommand1.ExecuteReader();
    OracleParameter pRes = new OracleParameter("C_REF", myReader);
    pRes.Direction = ParameterDirection.InputOutput;

    oracleCommand1.Parameters.Add("c_ref", pRes);

    while (myReader.Read())
    {
        MessageBox.Show(myReader.GetString(0)); // + ", " + myReader.GetString(myReader.GetOrdinal("contactemail")));
    }
    myReader.Close();

现在,虽然:我如何检索所有数据,而不是仅仅从一列中检索,正如我上面所做的那样?最好的情况是将结果集引导到DataGridView,但是如果必须的话,我可以将我想要的各种列连接起来(stringFormat())并以编程方式将它们添加到备忘录或其他类似的......

1 个答案:

答案 0 :(得分:3)

在我看来this page表示OracleDBType.Cursor类型不能在这里使用:

  

Oracle REF CURSOR。此类型没有相应的.NET Framework类型。 OracleDataReader对象可用于检索游标内容。

除非当然我误解了文档,这完全是可能的,因为我不做C#/ DevArt。