如何将数据表作为输入传递给C#中的过程?

时间:2012-08-19 07:57:06

标签: oracle c#-4.0

我写了将数据插入数据库表的存储过程但是我没有得到如何将数据表传递给存储过程,请告诉我如何使用它。

下面是我的storedprocedure

CREATE OR REPLACE PROCEDURE PR_SREE_TEST(p_recordset In SYS_REFCURSOR) IS

Contrac_rc SREE_TEST%rowtype;
BEGIN

   Loop
   Fetch p_recordset Into Contrac_rc;
   EXIT WHEN p_recordset%NOTFOUND;
       Insert into SREE_TEST(CT,DESC,FLAG)
       Values(Contrac_rc.CT,Contrac_rc.DESC,Contrac_rc.FLAG);

   End Loop;


   EXCEPTION
     WHEN NO_DATA_FOUND THEN
       NULL;
     WHEN OTHERS THEN
       -- Consider logging the error and then re-raise
       RAISE;
END PR_SREE_TEST;
/

和cs page

  public DataSet sreetest(DataTable dt)
        {
            DataSet dsRegularIndentdtl = new DataSet();
            try
            {
                OracleConnection OraConn = new OracleConnection(strDBConnection);
                OraConn.Open();

                OracleCommand OraCmd = new OracleCommand();
                OraCmd.Connection = OraConn;
                OraCmd.CommandText = "PR_SREE_TEST";
                OraCmd.CommandType = CommandType.StoredProcedure;
                OracleParameter parameter = new OracleParameter();


                var recordSet1 = new DataTable();
                recordSet1 = dt;
               OraCmd.Parameters.Add("p_recordset", OracleDbType.RefCursor, recordSet1, ParameterDirection.Input);
                 OraCmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return dsRegularIndentdtl;
        }
    }

上面是我的代码,它说p_recordset没有被验证。请告诉我如何执行它。

1 个答案:

答案 0 :(得分:0)

确保使用正确的OraCmd.Parameters.Add()重载,

根据msdn,第四个参数不是参数方向,如下所示

public OracleParameter Add(
    string parameterName,
    OracleType dataType,
    int size,
    string srcColumn
)