-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExecuteSQL.cs
More file actions
74 lines (70 loc) · 2.27 KB
/
ExecuteSQL.cs
File metadata and controls
74 lines (70 loc) · 2.27 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
73
74
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 ExecuteSQL
{
protected SqlCommand SqlCommand { get; set; }
protected SqlConnection SqlConnection { get; set; }
protected string ConnectionStringName { get; set; }
protected SqlCommand SetupSqlCommand(string procedureName, CommandType commandType)
{
try
{
SqlCommand sqlCommand = new SqlCommand();
sqlCommand.CommandText = procedureName;
sqlCommand.CommandType = commandType;
sqlCommand.Connection = SqlConnection;
return sqlCommand;
}
catch (Exception ex)
{
Console.WriteLine
("Catching the {0} exception triggers the finally block.",
ex.GetType());
throw;
}
}
protected SqlConnection SetupSQLConnection(string connectionStringName)
{
try
{
SqlConnection connection = new SqlConnection();
connection.ConnectionString = ConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString;
return connection;
}
catch (Exception ex)
{
Console.WriteLine
("Catching the {0} exception triggers the finally block.",
ex.GetType());
throw;
}
}
public DataSet Execute()
{
try
{
DataSet dataSet = new DataSet();
this.SqlConnection.Open();
SqlDataAdapter dataAdapter = new SqlDataAdapter(SqlCommand);
dataAdapter.Fill(dataSet, "results");
return dataSet;
}
catch (Exception ex)
{
this.SqlConnection.Close();
Console.WriteLine
("Catching the {0} exception triggers the finally block.",
ex.GetType());
throw;
}
}
}
}