通用存储过程函数

///

1<summary>   
2/// 执行存储过程,  Cnn数据库连接对象   
3/// </summary>

///

1<param name="parameter"/>

参数数组
///

1<param name="procudureName"/>

存储过程名称

public void excuPro(string procudureName,parameter [] proParameter)

{

SqlCommand cmd=new SqlCommand();
cmd.CommandType=System.Data.CommandType.StoredProcedure ;
cmd.CommandText=procudureName;
for(int i=0;i<parameter.Length;i++)
cmd.Parameters.Add(parameter[i]);
cmd.Connection=Cnn;

try
{
if(Cnn.State==System.Data.ConnectionState.Closed)
Cnn.Open();
return cmd.ExecuteReader();
}
catch(System.Data.SqlClient.SqlException e)
{
throw new Exception(e.Message );
}
finally
{
cmd.Dispose();
}
}

Published At
Categories with Web编程
Tagged with
comments powered by Disqus