关于ParameterDirection的疑惑

yhd913339578 2013-09-28 11:49:08
if ((parameters[index].Direction == ParameterDirection.InputOutput || parameters[index].Direction == ParameterDirection.Input) &&
(parameters[index].Value == null))
{
parameters[index].Value = DBNull.Value;
}

有什么用???
private static void AttachParameters(IDataParameter[] parameters, OracleCommand cmd)
{
if (parameters != null && parameters.Length > 0)
{
for(int index=0;index<parameters.Length;index++)
{
if (parameters[index] is OracleParameter)
{
if ((parameters[index].Direction == ParameterDirection.InputOutput || parameters[index].Direction == ParameterDirection.Input) &&
(parameters[index].Value == null))
{
parameters[index].Value = DBNull.Value;
}
cmd.Parameters.Add(parameters[index]);
}
else
{
OracleParameter parameter = new OracleParameter();
parameter.DbType = parameters[index].DbType;
parameter.Value = parameters[index].Value;
if ((parameter.Direction == ParameterDirection.InputOutput || parameter.Direction == ParameterDirection.Input) &&
(parameter.Value == null))
{
parameter.Value = DBNull.Value;
}
parameter.ParameterName = parameters[index].ParameterName;
cmd.Parameters.Add(parameter);
}
}
}
}
...全文
198 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
yhd913339578 2013-09-28
  • 打赏
  • 举报
回复
引用 4 楼 guwei4037 的回复:
存储过程中用的输入参数和输出参数。 条件1:InputOutput既可以是输入参数也可以是输出参数 条件2:Input输入参数 条件3:parameter.Value == null 参数的值为null 如果参数符合1或者2的前提下,并且符合3,执行parameter.Value = DBNull.Value;
如果是output参数会怎样??
全栈极简 2013-09-28
  • 打赏
  • 举报
回复
存储过程中用的输入参数和输出参数。 条件1:InputOutput既可以是输入参数也可以是输出参数 条件2:Input输入参数 条件3:parameter.Value == null 参数的值为null 如果参数符合1或者2的前提下,并且符合3,执行parameter.Value = DBNull.Value;
  • 打赏
  • 举报
回复
这个东西在if里边写一遍,在else里边也重复写一遍。
  • 打赏
  • 举报
回复
那个东西重复了两遍,你说有什么用? 如果它只写一遍,那么或许你值得问一问“有什么用”。如果它重复了两遍,它整个过程就是干这个事情的,你还问“有什么用”就奇怪了。 如果不理解,你就把这个方法删除掉好了!看看出什么错,通过测试你就就知道有什么用了。
yhd913339578 2013-09-28
  • 打赏
  • 举报
回复
求大师解惑啊啊啊啊啊啊
tcmakebest 2013-09-28
  • 打赏
  • 举报
回复 2
就是把输入参数为 null 值的改为 DBNull.Value,不然会报错的。 null 是 C# 的空值,DBNull.Value 是 SQL 的空值,懂了不?

111,125

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧