C#调用oracle存储过程的问题,有输入和输出参数,怎么调用执行存储过程获得输出值
1个回答
展开全部
public bool AddGroup(Group g)
{
con = new OracleConnection(ConDataBaseStr._connectionString);
cmd = new OracleCommand("Addgroup", con);
try
{
con.Open();
cmd.CommandType = CommandType.StoredProcedure;
OracleParameter[] parms = {
new OracleParameter("p_Groupname",OracleDbType.Varchar2,20),
new OracleParameter("p_Groupbz",OracleDbType.Varchar2,40),
new OracleParameter("p_Count",OracleDbType.Int16)
};
parms[0].Value = g.groupName;
parms[1].Value = g.groupBz;
parms[2].Direction = ParameterDirection.Output;
foreach (OracleParameter parm in parms)
{
cmd.Parameters.Add(parm);
}
cmd.ExecuteNonQuery();
short bj = Convert.ToInt16(cmd.Parameters[2].Value.ToString());
con.Close();
parms = null;
if (bj == 1)
return true;
else
return false;
}
catch (System.Exception ex)
{
return false;
}
finally
{
cmd.Dispose();
con.Close();
}
}
{
con = new OracleConnection(ConDataBaseStr._connectionString);
cmd = new OracleCommand("Addgroup", con);
try
{
con.Open();
cmd.CommandType = CommandType.StoredProcedure;
OracleParameter[] parms = {
new OracleParameter("p_Groupname",OracleDbType.Varchar2,20),
new OracleParameter("p_Groupbz",OracleDbType.Varchar2,40),
new OracleParameter("p_Count",OracleDbType.Int16)
};
parms[0].Value = g.groupName;
parms[1].Value = g.groupBz;
parms[2].Direction = ParameterDirection.Output;
foreach (OracleParameter parm in parms)
{
cmd.Parameters.Add(parm);
}
cmd.ExecuteNonQuery();
short bj = Convert.ToInt16(cmd.Parameters[2].Value.ToString());
con.Close();
parms = null;
if (bj == 1)
return true;
else
return false;
}
catch (System.Exception ex)
{
return false;
}
finally
{
cmd.Dispose();
con.Close();
}
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询