-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExecuteStoreProcedure.cs
More file actions
72 lines (68 loc) · 2.24 KB
/
ExecuteStoreProcedure.cs
File metadata and controls
72 lines (68 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace ExecuteSQL
{
public class ExecuteStoredProcedure : ExecuteSQL
{
private string ProcedureName { get; set; }
public ExecuteStoredProcedure(string connectionStringName, string procedureName)
{
try
{
this.SqlConnection = this.SetupSQLConnection(connectionStringName);
this.ProcedureName = null;
this.SqlCommand = this.SetupSqlCommand(procedureName, CommandType.StoredProcedure);
}
catch(Exception ex)
{
Console.WriteLine
("Catching the {0} exception triggers the finally block.",
ex.GetType());
throw;
}
}
public ExecuteStoredProcedure(string connectionStringName, string procedureName, List<SqlParameter> parameters)
{
try
{
this.SqlConnection = this.SetupSQLConnection(connectionStringName);
this.ProcedureName = procedureName;
this.SqlCommand = this.SetupSqlCommand(procedureName, CommandType.StoredProcedure);
SetupSQLParameters(parameters);
}
catch(Exception ex)
{
Console.WriteLine
("Catching the {0} exception triggers the finally block.",
ex.GetType());
throw;
}
}
public void SetupSQLParameters(List<SqlParameter> sqlParameters)
{
try
{
if (sqlParameters.Count > 0)
{
foreach (SqlParameter param in sqlParameters)
{
this.SqlCommand.Parameters.Add(param);
}
}
}
catch (Exception ex)
{
Console.WriteLine
("Catching the {0} exception triggers the finally block.",
ex.GetType());
throw;
}
}
}
}