我想從Oracle過程返回數據以填充某些Label控件。該過程接受26個輸入參數(搜索變量)並返回3個輸出遊標。 我已經成功地從使用OracleCommand,DataAdapter和DataSet返回單個引用遊標的過程返回數據,但是已經有各種問題從返回多個ref遊標的過程返回數據。從Oracle過程使用DAAB和C返回多個ref遊標#
我試圖從企業庫中使用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;
任何想法?我傾向於使用不當的閱讀器,但無法弄清楚我錯過了什麼。 謝謝。
只需設置答案標誌以防止問題出現在未答覆的部分。 – ScottLenart 2009-12-14 16:31:18