现在的位置: 首页 > 综合 > 正文

asp.net调用Oracle存储过程,获取返回值!(例子)

2013年04月04日 ⁄ 综合 ⁄ 共 1925字 ⁄ 字号 评论关闭
OracleConnection conn = new OracleConnection(SQLHelper.GetConnectionString());//SQLHelper.GetConnectionString()——连接字符串
OracleCommand cmd = new OracleCommand("pkg_car_state.proc_upd_car_model_state", conn);//创建command对象
cmd.CommandType = CommandType.StoredProcedure;//设置CommandType类型

//设置参数
OracleParameter[] prams = { new OracleParameter("p_old_car_model_id", OracleType.Int16),
                      new OracleParameter("p_new_car_model_id", OracleType.Int32),
                      new OracleParameter("p_tk_store_id", OracleType.Int32),
                      new OracleParameter("p_bk_store_id", OracleType.Int32),
                      new OracleParameter("p_begin_date", OracleType.DateTime),
                      new OracleParameter("p_end_date", OracleType.DateTime),
                      new OracleParameter("p_cur_use_no", OracleType.VarChar,50),
                      new OracleParameter("p_use_mode", OracleType.VarChar,50),
                      new OracleParameter("p_user_id", OracleType.Int32),
                      new OracleParameter("p_rst_code", OracleType.VarChar,50),
                      new OracleParameter("p_rst_msg", OracleType.VarChar,50)};

prams[0].Direction = ParameterDirection.Input;
prams[1].Direction = ParameterDirection.Input;
prams[2].Direction = ParameterDirection.Input;
prams[3].Direction = ParameterDirection.Input;
prams[4].Direction = ParameterDirection.Input;
prams[5].Direction = ParameterDirection.Input;
prams[6].Direction = ParameterDirection.Input;
prams[7].Direction = ParameterDirection.Input;
prams[8].Direction = ParameterDirection.Input;
prams[9].Direction = ParameterDirection.Output;
prams[10].Direction = ParameterDirection.Output;

//参数赋值
prams[0].Value = 0;
prams[1].Value = order.CarModelID;
prams[2].Value = order.TakeBelongStoreId;
prams[3].Value = order.BackBelongStoreId;
prams[4].Value = order.TakeCarDate;
prams[5].Value = order.BackCarDate;

prams[6].Value = boNo;
prams[7].Value = "租赁";
prams[8].Value = 134;
           
for (int i = 0; i < prams.Length; i++)
{
    cmd.Parameters.Add(prams[i]);
}

OracleDataAdapter caChe = new OracleDataAdapter(cmd);
DataTable datatable = new DataTable();
caChe.Fill(datatable);

//获取返回值
string tempStr = prams[9].Value.ToString();//返回代码;0表示成功,非0表示不成功
string reMsg = prams[10].Value.ToString();//返回提示信息

抱歉!评论已关闭.