我想从 Oracle 过程返回数据以填充一些标签控件。该过程接受 26 个输入参数(搜索变量)并返回 3 个输出游标。我已经成功地从使用 OracleCommand、DataAdapter 和 DataSet 返回单个引用游标的过程中返回数据,但是从返回多个引用游标的过程中返回数据时遇到了各种问题。
我试图使用 Enterprise Library 中的 DAAB,但没有成功(原始帖子)。我现在回到了基于 Oracle 和其他开发站点的帖子的 OracleCommand。我仍然返回零行。我可以使用“rdr_p_cursor_detail.GetName(0);”从我的读者那里返回列名,但是当我尝试返回一个值时,我得到一个“由于对象的当前状态,操作无效”。错误。
//Open the connection to Oracle.
OracleConnection cn = new OracleConnection(ConfigurationHelper.ConnectionStringSlabProcedures);
OracleCommand cmd = new OracleCommand();
cn.Open();
cmd.Connection = cn;
try
{
//Set the command text (SQL) of the Oracle command to the stored procedure "getSlab", which returns slab details.
cmd.CommandText = ConfigurationHelper.ProcuedurePackageSchema + "." +
ConfigurationHelper.ProcuedurePackageName + "." +
"getSlab";
//...and specify the command as a stored procedure.
cmd.CommandType = CommandType.StoredProcedure;
//Add the input and output parameters.
cmd.Parameters.Add("rb_category", OracleDbType.Varchar2).Value = string.Empty;
cmd.Parameters.Add("rb_category_value", OracleDbType.Varchar2).Value = slabID;
cmd.Parameters.Add("rb_type ", OracleDbType.Varchar2).Value = string.Empty;
cmd.Parameters.Add("rb_chem_value", OracleDbType.Varchar2).Value = string.Empty;
cmd.Parameters.Add("cb_inside_only", OracleDbType.Varchar2).Value = string.Empty;
cmd.Parameters.Add("cb_appl_pending", OracleDbType.Varchar2).Value = string.Empty;
cmd.Parameters.Add("cb_appl_soft_approved", OracleDbType.Varchar2).Value = string.Empty;
cmd.Parameters.Add("cb_appl_hard_approved", OracleDbType.Varchar2).Value = string.Empty;
cmd.Parameters.Add("cb_appl_mechanically", OracleDbType.Varchar2).Value = string.Empty;
cmd.Parameters.Add("cb_as_cast", OracleDbType.Varchar2).Value = string.Empty;
cmd.Parameters.Add("cb_as_dispoed", OracleDbType.Varchar2).Value = string.Empty;
cmd.Parameters.Add("cb_chem_match", OracleDbType.Varchar2).Value = string.Empty;
cmd.Parameters.Add("cb_near_match", OracleDbType.Varchar2).Value = string.Empty;
cmd.Parameters.Add("txt_width_min", OracleDbType.Int32).Value = 0;
cmd.Parameters.Add("txt_width_max", OracleDbType.Int32).Value = 0;
cmd.Parameters.Add("txt_quality_min", OracleDbType.Int32).Value = 0;
cmd.Parameters.Add("txt_quality_max", OracleDbType.Int32).Value = 0;
cmd.Parameters.Add("txt_days_old_min", OracleDbType.Int32).Value = 0;
cmd.Parameters.Add("txt_days_old_max", OracleDbType.Int32).Value = 0;
cmd.Parameters.Add("txt_days_rev_min", OracleDbType.Int32).Value = 0;
cmd.Parameters.Add("txt_days_rev_max", OracleDbType.Int32).Value = 0;
cmd.Parameters.Add("txt_reviewer", OracleDbType.Varchar2).Value = string.Empty;
cmd.Parameters.Add("cb_excl_hr", OracleDbType.Varchar2).Value = string.Empty;
cmd.Parameters.Add("cb_excl_cr", OracleDbType.Varchar2).Value = string.Empty;
cmd.Parameters.Add("cb_excl_galv", OracleDbType.Varchar2).Value = string.Empty;
cmd.Parameters.Add("cb_excl_tin", OracleDbType.Varchar2).Value = string.Empty;
//Add the ref-cursors as output parameters
OracleParameter p_cursor_detail = cmd.Parameters.Add("p_cursor_detail", OracleDbType.RefCursor);
p_cursor_detail.Direction = ParameterDirection.Output;
OracleParameter p_cursor_comments = cmd.Parameters.Add("p_cursor_comments", OracleDbType.RefCursor);
p_cursor_comments.Direction = ParameterDirection.Output;
OracleParameter p_cursor_grades = cmd.Parameters.Add("p_cursor_grades", OracleDbType.RefCursor);
p_cursor_grades.Direction = ParameterDirection.Output;
// Execute the command
cmd.ExecuteNonQuery();
// Construct an OracleDataReader from the REF CURSOR
OracleDataReader rdr_p_cursor_detail = ((OracleRefCursor)p_cursor_detail.Value).GetDataReader();
if (rdr_p_cursor_detail.Read())
{
//This would return an error if it was outside this if statement.
//"Operation is not valid due to the current state of the object."
OracleString oracleString1 = rdr_p_cursor_detail.GetOracleString(1);
LabelSlabID.Text = oracleString1.ToString();
//This correctly returns column name/header.
//LabelSlabID.Text = rdr_p_cursor_detail.GetName(0);
}
else
{
LabelSlabID.Text = "No Data";
}
rdr_p_cursor_detail.Close();
rdr_p_cursor_detail.Dispose();
p_cursor_detail.Dispose();
p_cursor_comments.Dispose();
p_cursor_grades.Dispose();
}
catch (Exception e)
截断的 oracle 程序:
PROCEDURE getSlab
(rb_category IN VARCHAR2
,rb_category_value IN VARCHAR2
,rb_type IN VARCHAR2
,rb_chem_value IN VARCHAR2
,cb_inside_only IN VARCHAR2
,cb_appl_pending IN VARCHAR2
,cb_appl_soft_approved IN VARCHAR2
,cb_appl_hard_approved IN VARCHAR2
,cb_appl_mechanically IN VARCHAR2
,cb_as_cast IN VARCHAR2
,cb_as_dispoed IN VARCHAR2
,cb_chem_match IN VARCHAR2
,cb_near_match IN VARCHAR2
,txt_width_min IN NUMBER
,txt_width_max IN NUMBER
,txt_quality_min IN NUMBER
,txt_quality_max IN NUMBER
,txt_days_old_min IN NUMBER
,txt_days_old_max IN NUMBER
,txt_days_rev_min IN NUMBER
,txt_days_rev_max IN NUMBER
,txt_reviewer IN VARCHAR2
,cb_excl_hr IN VARCHAR2
,cb_excl_cr IN VARCHAR2
,cb_excl_galv IN VARCHAR2
,cb_excl_tin IN VARCHAR2
,cur_OUT OUT t_cursor1
,cur_OUT1 OUT t_cursor2
,cur_OUT2 OUT t_cursor3) IS
--All the queries and so forth are performed and data sent to temp tables.
OPEN v_cursor1 FOR
SELECT * FROM TABLE(CAST(g_slab_table AS getSlab_table));
cur_OUT := v_cursor1;
OPEN v_cursor2 FOR
SELECT * FROM TABLE(CAST(g_comment_table AS getComment_table));
cur_OUT1 := v_cursor2;
OPEN v_cursor3 FOR
SELECT * FROM TABLE(CAST(g_grades_table AS getGrades_table));
cur_OUT2 := v_cursor2;
有任何想法吗?我倾向于不正确的阅读器使用,但无法弄清楚我错过了什么。谢谢。