我在将返回参数传递给第二个下拉列表时遇到问题。第二个列表完全取决于第一个列表的选择。我很确定SP很好。同样,我的问题是传递价值。
存储过程
PROCEDURE ev_dropdown(
cur_out IN OUT eqpack.t_cur_out,
p_result OUT VARCHAR2,
p_reference_id IN NUMBER
)
IS
BEGIN
OPEN cur_out FOR
SELECT ev_id, ev
FROM event WHERE a_ref = p_reference_id;
EXCEPTION
WHEN OTHERS
THEN
p_result :=
'An error occurred in get_events_dropdown - ' || SQLERRM;
END ev_dropdown;
的.cs
public void populateSpecificEv(int p)
{
DataTable dtRef = CreateReferenceDT();
string conn = GetConnectString();
using (OracleConnection connection = new OracleConnection(conn))
using (OracleCommand command = connection.CreateCommand())
{
command.CommandText = "eqpackage.get_events_dropdown";
command.CommandType = CommandType.StoredProcedure;
command.Parameters["p_reference_id"].Value = p;
OracleDataReader reader;
reader = command.ExecuteReader();
dtRef.Rows.Add("0", "-select-");
while (reader.Read())
{
dtRef.Rows.Add(reader[0], reader[1]);
}
connection.Open();
command.ExecuteNonQuery();
command.Connection.Close();
command.Connection.Dispose();
return dtRef; //Error -returns void, a return keyword must not be followed by an object expression
}
}
DataTable CreateReferenceDT()
{
DataTable dt = new DataTable();
dt.Columns.Add("id", typeof(int));
dt.Columns.Add("name", typeof(string));
return dt;
}
aspx.cs
protected void ddlSys_SelectedIndexChanged1(object sender, EventArgs e)
{
int p = int.Parse(ddlSystems.SelectedItem.Value);
dbase.populateSpecificEvent(p);
DataTable dt1 = dbase.PopulateEvDropDown();
ddlEv.DataSource = dt1;
ddlEv.DataTextField = "name";
ddlEv.DataValueField = "id";
ddlEv.DataBind();
}
答案 0 :(得分:0)
我相信你想要更新你的存储过程实际只是执行一个SELECT语句而不显式创建自己的游标。然后你会调用command.ExecuteQuery()(我看到你正在做),这将返回一个IDataReader,它基本上只是一个只进,只读游标。
我会删除以下额外的行:
connection.Open();
command.ExecuteNonQuery();
command.Connection.Close();
command.Connection.Dispose();
如果您将存储过程更改为实际上只是一个select语句,那么您可以使用while(reader.Read())
循环一次一个地读取行,并将它们插入DataTable
,或者只是致电DataTable.Load(IDataReader)。