我在oracle 下做了个procedure
在 sqlplus 中执行 传入三个空参数,两个输入参数,一个输出参数.执行结果成功!
可为什么我在C#中调用时传入空参数就报错???
Message: "Parameter 'p_UserPwd': No size set for variable length data type: String."
在 sqlplus 中执行 传入三个空参数,两个输入参数,一个输出参数.执行结果成功!
可为什么我在C#中调用时传入空参数就报错???
Message: "Parameter 'p_UserPwd': No size set for variable length data type: String."
http://community.csdn.net/Expert/topic/4470/4470574.xml?
如果是""用DBNull.Value代替.
看来这年头还是有好人!
你们说的方法我都试过了,可还是失败!
create or replace procedure GetUser
(p_UserId in varchar2,p_UserPwd in varchar2,p_cnt out number)
is v_cnt number;
begin
select count(a.user_Name) into v_cnt
from Usr_inf a, user_Pwd b where a.User_Id=b.User_Id and a.mod_Dte=b.crt_Dte
and b.User_Id=p_UserId and b.Pass_Word=p_UserPwd;
p_cnt:=v_cnt;
dbms_OUtPUt.put_line(to_char(v_cnt));
end;C#调用:
public bool GetUser(string UserId,string UserPwd)
{
try
{
if(MyConn.State==ConnectionState.Closed)
MyConn.Open();
Cmd=new OracleCommand("GetUser",MyConn);
Cmd.CommandType=CommandType.StoredProcedure;
Cmd.Parameters.Add("p_cnt",OracleType.Number);
Cmd.Parameters["p_cnt"].Direction=ParameterDirection.Output;
Cmd.Parameters.Add("p_UserPwd",UserPwd);
Cmd.Parameters.Add("p_UserId",UserId);
Cmd.ExecuteNonQuery();
return Convert.ToInt32(Cmd.Parameters["p_cnt"].Value)<=0 ? false:true;
}
catch(Exception ex)
{
MessageBox.Show("GetUser 失败:"+ex.Message+"\r\t"+ex.ToString(),Title,
MessageBoxButtons.OK,MessageBoxIcon.Error);
return false;
}
finally
{
MyConn.Close();
}
}
-->Cmd.Parameters.Add("p_UserPwd",UserPwd == String.Empty ? null : UserPwd);Cmd.Parameters.Add("p_UserId",UserId);
-->Cmd.Parameters.Add("p_UserId",UserId == String.Empty ? null : UserId);
______________
这句错误是说你写的字符串参数变量没有指定大小,我以前遇到过,在ORACLE中,如果参数为空,即空串的时候没有指定大小就会出现这样的情况,建议把类型的大小写上去应该解决,楼主可以试试:_)
例如:
OracleParameter pwdParam = cmd.Parameters.Add("p_UserPwd", OracleType.VarChar,100);
pwdParam.Value = UserPwd;