0

程序名称:AGENCY_STATE_REPORT

输入:

(frm_date date, 
 to_date1 date)

输出;

p_cur out SYS_REFCURSOR

我的 C# 代码:

public DataTable retdt1(string frmdate,string todate)
{
    try
    {
        // Logfile("retdt", query);
        con.Open();

        if (con.State == ConnectionState.Open)
        {
            objCmd = new OracleCommand();
            objCmd.CommandText = "AGENCY_STATE_REPORT ";
            objCmd.CommandType = CommandType.StoredProcedure;

            objCmd.Parameters.Add("@frm_date",OracleDbType.Date).Value=frmdate;
            objCmd.Parameters.Add("to_date1", OracleDbType.Date).Value = todate;
            objCmd.Parameters["@ p_cur"].Direction = ParameterDirection.Output;

            dap = new OracleDataAdapter(objCmd);
            dt = new DataTable();

            dap.Fill(dt);

            if (dt.Rows.Count > 0)
            {
                return dt;
            }
        }

        return null;
    }
    catch (Exception ex)
    {
        HttpContext.Current.Response.Write(ex.Message);
        throw ex;
    }
    finally
    {
        if (con != null)
            if (con.State != ConnectionState.Closed)
                con.Close();

        if (objCmd != null)
        {
            objCmd.Dispose();
            dap.Dispose();
            dt.Dispose();
        }
    }
}

我知道这是错误的代码,但是如何将这两个输入参数发送到存储过程?

4

1 回答 1

0

自动填充 绑定 GridView 到动态 DataTable

您还可以通过实施“使用”块来失去手动处理,例如:-

using (var cnn = new SqlConnection(WebConfigurationManager.ConnectionStrings["MyConnection"].ConnectionString))
                {
                    cnn.Open();

                    using (var cmd = new SqlCommand(sql.ToString(), cnn))
                    {
                        cmd.CommandType = System.Data.CommandType.Text;    
                        cmd.ExecuteNonQuery();
                    }
                }
于 2018-01-30T16:48:25.083 回答