执行一下这个sql:
SELECT B.[name], C.[name] AS [type], B.length, B.isoutparam, B.isnullable
FROM sysobjects AS A INNER JOIN";
syscolumns AS B ON A.id = B.id AND A.xtype = 'P' AND A.name = '你的存储过程名' INNER JOIN
systypes C ON B.xtype = C.xtype AND C.[name] <> 'sysname'
ORDER BY ROW_NUMBER() OVER (ORDER BY B.id), B.isoutparam
看到结果了吧,此时此刻你是否有豁然开朗的感觉?
正是源于此,下面这个类就有了用武之地,从此不用繁琐的配置存储过程参数
using System;
using System.Collections;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using System.Xml;
namespace fnSwordLibrary.DataBase
{
public class CEx_SqlProcedure
{
#region 数据成员
private SqlConnection _SqlConnection = null;
private String _Procedure = String.Empty;
private SqlCommand _SqlCmd = new SqlCommand();
private Hashtable _InputTable = null; // 保存input参数和值
private String _LastError = String.Empty;
#endregion
#region 构造函数
public CEx_SqlProcedure()
{
_InputTable = new Hashtable();
_SqlCmd.CommandType = CommandType.StoredProcedure;
}
public CEx_SqlProcedure(SqlConnection SqlConnection)
: this()
{
this.SqlConnection = SqlConnection;
}
public CEx_SqlProcedure(String Procedure, SqlConnection SqlConnection)
: this()
{
this.SqlConnection = SqlConnection;
this.Procedure = Procedure;
}
#endregion
#region 属性
public String LastError
{
get
{
return this._LastError;
}
}
public Object ReturnValue
{
get
{
return _SqlCmd.Parameters["RetVal"].Value;
}
}
public SqlConnection SqlConnection
{
set
{
this._SqlConnection = value;
_SqlCmd.Connection = this._SqlConnection;
}
}
public String Procedure
{
set
{
this._Procedure = value;
_SqlCmd.CommandText = this._Procedure;
}
get
{
return this._Procedure;
}
}
#endregion
#region 公共方法
/// <summary>
/// 执行存储过程,仅返回是否成功标志
/// </summary>
/// <param name="Procedure">存储过程名</param>
/// <returns>是否成功标志</returns>
public Boolean ExecuteNonQuery(String Procedure)
{
this.Procedure = Procedure;
return ExecuteNonQuery();
}
/// <summary>
/// 执行存储过程,