oracle数据库中有一个function fun_sin_shift_to_group 两个参数分别是 INDATE IN DATE , inshift in Integer,一个返回值 返回值为varchar2
用oracleclient可以传参数并获得返回值,这是没问题的(代码如下:)
OracleConnection oc = new OracleConnection("data source=l3ironbe;User Id=level3;Password=wisdri");
OracleCommand ocmd = new OracleCommand();
OracleParameter op1 = new OracleParameter("INDATE", OracleType.DateTime);
op1.Value = dt;
OracleParameter op2 = new OracleParameter("inshift", OracleType.Int32);
op2.Value = shift;
OracleParameter op3 = new OracleParameter();
op3.OracleType = OracleType.VarChar;
op3.Size = 5;
op3.Direction = ParameterDirection.ReturnValue;
;
ocmd.Parameters.Add(op1);
ocmd.Parameters.Add(op2);
ocmd.Parameters.Add(op3);
ocmd.Connection = oc;
ocmd.CommandText = "fun_sin_shift_to_group";
ocmd.CommandType = CommandType.StoredProcedure;
oc.Open();
ocmd.ExecuteNonQuery();
oc.Close();
group = op3.Value.ToString();
return group;
但是用oledb的访问就不行了:
OleDbConnection con = new OleDbConnection(connStr);
OleDbCommand com = new OleDbCommand();
com.Connection = con;
com.CommandType = CommandType.StoredProcedure;
com.CommandText = "fun_sin_shift_to_group";
OleDbParameter p1 = new OleDbParameter("INDATE", OleDbType.Date);
p1.Direction = System.Data.ParameterDirection.Input;
p1.Value = dt;
OleDbParameter p2 = new OleDbParameter("inshift", OleDbType.Integer);
p2.Direction = System.Data.ParameterDirection.Input;
p2.Value = shift;
OleDbParameter p3 = new OleDbParameter("groupid",OleDbType.VarChar);
p3.Size = 5;
p3.Direction = System.Data.ParameterDirection.Output;
com.Parameters.Add(p1);
com.Parameters.Add(p2);
com.Parameters.Add(p3);
总是异常,说参数数目不对或者类型不对,我试着简化参数,或者Oledbtype设置可能的类型,都是这样的异常;
非常奇怪,怎么回事?
另外我目前绕过这个问题的办法:
在oracle中建一个procedure 调用这个function
CREATE OR REPLACE Procedure pro_sin_shift_to_group(INDATE IN DATE , inshift in Integer ,groupid Out Varchar)
IS
BEGIN
groupid:=fun_sin_shift_to_group(indate,inshift);
END;
然后把上面oledb代码中com.CommandText = "pro_sin_shift_to_group";该成