2012-06-22 205 views
0

我有一個問題將返回參數傳遞給第二個下拉列表。第二個列表完全依賴於第一個列表中的選擇。我很確定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

我相信你想更新您的存儲過程,而不明確地實際上只是執行SELECT語句創建自己的光標。然後你會打電話command.ExecuteQuery()(我看到你在做什麼),這將返回一個IDataReader,它基本上是一個只向前,只讀光標。

我會刪除下列多餘的線條:

connection.Open(); 
command.ExecuteNonQuery(); 
command.Connection.Close(); 
command.Connection.Dispose(); 

如果您改變了存儲過程實際上只是一個SELECT語句,那麼您可以使用您while(reader.Read())循環在時間中的行讀取,一個,並將它們插入到DataTable中,或者直接撥打DataTable.Load(IDataReader)

相關問題