IDataParameter[] paramArray = new IDataParameter[]{ AdoHelper.GetParameter("ReturnValue",DbType.Int32,ParameterDirection.ReturnValue), AdoHelper.GetParameter("inintPageIndex",DbType.Int32,pageIndex), AdoHelper.GetParameter("inintPageSize",DbType.Int32,pageSize), AdoHelper.GetParameter("outcurlist",DbType.Object,ParameterDirection.Output) };
ParameterDirection是一个枚举类型,提供了四种参数类型:
// 摘要: // 指定查询内的有关 System.Data.DataSet 的参数的类型。 public enum ParameterDirection { // 摘要: // 参数是输入参数。 Input = 1, // // 摘要: // 参数是输出参数。 Output = 2, // // 摘要: // 参数既能输入,也能输出。 InputOutput = 3, // // 摘要: // 参数表示诸如存储过程、内置函数或用户定义函数之类的操作的返回值。 ReturnValue = 6, }
.Net中的参数定义为形式参数而把存储过程的参数定义为实际参数
数据库存储过程的实际参数如果没有默认值则形式参数必须传值给实际参数
但是如果形式参数的类型为ParameterDirection.Output 则传给实际参数的永远是空值
果形式参数的类型为ParameterDirection.ReturnValue 则形式参数不会传值给实际参数 实际参数必须有默认值 否则代码会报错
如果形式参数类型为ParameterDirection.InputOutput 或者 ParameterDirection.Output 则实际参数必须有output 关键字
另外需要注意的是在.net中System.DBNull.Value表示数据库参数为空值而不是null