通用存储过程函数
1/**//// <summary>
2 /// 执行存储过程,Cnn数据库连接对象
3 /// </summary>
4 /// <param name="parameter">参数数组</param>
5 /// <param name="procudureName">存储过程名称</param>
6
7public void excuPro(string procudureName,parameter [] proParameter)
8
9{
10
11
12
13SqlCommand cmd=new SqlCommand();
14 cmd.CommandType=System.Data.CommandType.StoredProcedure ;
15 cmd.CommandText=procudureName;
16 for(int i=0;i<parameter.Length;i++)
17 cmd.Parameters.Add(parameter[i]);
18 cmd.Connection=Cnn;
19
20 try
21 {
22 if(Cnn.State==System.Data.ConnectionState.Closed)
23 Cnn.Open();
24 return cmd.ExecuteReader();
25 }
26 catch(System.Data.SqlClient.SqlException e)
27 {
28 throw new Exception(e.Message );
29 }
30 finally
31 {
32 cmd.Dispose();
33 }
34}
2 /// 执行存储过程,Cnn数据库连接对象
3 /// </summary>
4 /// <param name="parameter">参数数组</param>
5 /// <param name="procudureName">存储过程名称</param>
6
7public void excuPro(string procudureName,parameter [] proParameter)
8
9{
10
11
12
13SqlCommand cmd=new SqlCommand();
14 cmd.CommandType=System.Data.CommandType.StoredProcedure ;
15 cmd.CommandText=procudureName;
16 for(int i=0;i<parameter.Length;i++)
17 cmd.Parameters.Add(parameter[i]);
18 cmd.Connection=Cnn;
19
20 try
21 {
22 if(Cnn.State==System.Data.ConnectionState.Closed)
23 Cnn.Open();
24 return cmd.ExecuteReader();
25 }
26 catch(System.Data.SqlClient.SqlException e)
27 {
28 throw new Exception(e.Message );
29 }
30 finally
31 {
32 cmd.Dispose();
33 }
34}