Repository navigation
Expand file tree
/
Copy pathGenericDataBase.cs
More file actions
71 lines (58 loc) · 2.29 KB
/
Copy pathGenericDataBase.cs
File metadata and controls
71 lines (58 loc) · 2.29 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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
namespace ManualInsert
{
class GenericDataBase
{
public static SqlConnection conexion = new SqlConnection();
public static SqlConnectionStringBuilder conectionString = new SqlConnectionStringBuilder();
private static SqlCommand command = new SqlCommand();
public static void Connectar(String _connectionString)
{
GenericDataBase.GenericConn(_connectionString);
}
public static void Connectar()
{
GenericDataBase.GenericConn(GenericDataBase.conectionString.ConnectionString);
}
private static void GenericConn(string _connectionString)
{
if (GenericDataBase.conexion.State == System.Data.ConnectionState.Open)
{
GenericDataBase.conexion.Close();
}
GenericDataBase.conexion.ConnectionString = _connectionString;
try
{
GenericDataBase.conexion.Open();
}catch(Exception e)
{
throw e;
}
}
public static System.Data.DataTable GetTableProperty(String tableName)
{
GenericDataBase.command.Connection = GenericDataBase.conexion;
GenericDataBase.command.CommandText = "SELECT TABLE_NAME, COLUMN_NAME, DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '" + tableName + "'";
System.Data.DataTable dataTable = new System.Data.DataTable();
dataTable.Load(GenericDataBase.command.ExecuteReader());
return dataTable;
}
public static System.Data.DataTable GetRecords(string tableName, string where = "")
{
GenericDataBase.command.Connection = GenericDataBase.conexion;
GenericDataBase.command.CommandText = "SELECT * FROM " + tableName;
if (where != "")
{
GenericDataBase.command.CommandText += " WHERE " + where;
}
System.Data.DataTable dataTable = new System.Data.DataTable();
dataTable.Load(GenericDataBase.command.ExecuteReader());
return dataTable;
}
}
}