/// <summary>
/// 执行存储过程
/// </summary>
/// <param name="spName">存储过程名称</param>
/// <param name="paramInfos">存储过程(字段-值)对</param>
/// <returns></returns>
protected IList ExecuteStoredProc(
string spName, Dictionary<
string,
string> paramInfos)
![InBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/d608a01840fefd0e145dfeac03617766.png)
{
![InBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/d608a01840fefd0e145dfeac03617766.png)
IList result =
new ArrayList();
![InBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/d608a01840fefd0e145dfeac03617766.png)
ISessionFactoryImplementor s = (ISessionFactoryImplementor)cfg.BuildSessionFactory();
![InBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/d608a01840fefd0e145dfeac03617766.png)
IDbCommand cmd = ((NHibernate.Driver.SqlClientDriver)s.ConnectionProvider.Driver).CreateCommand();
![InBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/d608a01840fefd0e145dfeac03617766.png)
cmd.CommandText = spName;
![InBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/d608a01840fefd0e145dfeac03617766.png)
cmd.CommandType = CommandType.StoredProcedure;
// 加入参数
if (paramInfos !=
null)
![InBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/d608a01840fefd0e145dfeac03617766.png)
{
foreach (KeyValuePair<
string,
string> de
in paramInfos)
![InBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/d608a01840fefd0e145dfeac03617766.png)
{
![InBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/d608a01840fefd0e145dfeac03617766.png)
IDbDataParameter parameter = cmd.CreateParameter();
![InBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/d608a01840fefd0e145dfeac03617766.png)
parameter.ParameterName = de.Key.ToString();
// driver.FormatNameForSql( info.Name );
![InBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/d608a01840fefd0e145dfeac03617766.png)
parameter.Value = de.Value;
![InBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/d608a01840fefd0e145dfeac03617766.png)
cmd.Parameters.Add(parameter);
![InBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/d608a01840fefd0e145dfeac03617766.png)
}
![InBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/d608a01840fefd0e145dfeac03617766.png)
}
![InBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/d608a01840fefd0e145dfeac03617766.png)
IDbConnection conn = s.OpenConnection();
try
![InBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/d608a01840fefd0e145dfeac03617766.png)
{
![InBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/d608a01840fefd0e145dfeac03617766.png)
cmd.Connection = conn;
![InBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/d608a01840fefd0e145dfeac03617766.png)
IDataReader rs = cmd.ExecuteReader();
while (rs.Read())
![InBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/d608a01840fefd0e145dfeac03617766.png)
{
int fieldCount = rs.FieldCount;
![InBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/d608a01840fefd0e145dfeac03617766.png)
List<
object> list =
new List<
object>();
object[] values =
new Object[fieldCount];
for (
int i = 0; i < fieldCount; i++)
![InBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/d608a01840fefd0e145dfeac03617766.png)
values[i] = rs.GetValue(i);
![InBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/d608a01840fefd0e145dfeac03617766.png)
result.Add(values);
![InBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/d608a01840fefd0e145dfeac03617766.png)
}
![InBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/d608a01840fefd0e145dfeac03617766.png)
}
finally
![InBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/d608a01840fefd0e145dfeac03617766.png)
{
![InBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/d608a01840fefd0e145dfeac03617766.png)
s.CloseConnection(conn);
![InBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/d608a01840fefd0e145dfeac03617766.png)
}
return result;
![InBlock.gif](https://i-blog.csdnimg.cn/blog_migrate/d608a01840fefd0e145dfeac03617766.png)
}