-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBIOSUP_SQL.cs
More file actions
72 lines (67 loc) · 1.92 KB
/
Copy pathBIOSUP_SQL.cs
File metadata and controls
72 lines (67 loc) · 1.92 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.Data;
//using System.Data.SqlClient;
using MySql.Data.MySqlClient;
using System.Windows.Forms;
namespace BiosupCS
{
public class BIOSUP_SQL
{
MySqlConnection SQLConn;
//public SqlDataReader Bios_Data_Reader = null;
//public SqlConnection connection;
public BIOSUP_SQL(String str_connection)
{
try
{
SQLConn = new MySqlConnection(str_connection);
SQLConn.Open();
Console.WriteLine(SQLConn.ServerVersion.ToString());
}
catch
{
MessageBox.Show("Could not connect to SQL DB", "Error");
throw new Exception("Database Connection Error");
}
}
public DataTable BIOSUP_SQL_GET(String str_SQL)
{
try
{
ReopenConnections();
Console.WriteLine(str_SQL);
MySqlCommand cmd = new MySqlCommand(str_SQL, SQLConn);
DataTable dt = new DataTable();
dt.Load(cmd.ExecuteReader());
return dt;
}
// Handle any errors that may have occurred.
catch (Exception e)
{
Console.WriteLine(e);
throw;
}
}
public void BIOSUP_SQL_SET(String str_SQL)
{
Console.WriteLine(str_SQL);
ReopenConnections();
MySqlCommand cmd = new MySqlCommand(str_SQL, SQLConn);
cmd.ExecuteNonQuery();
SQLConn.Close();
}
public void ReopenConnections()
{
try
{
SQLConn.Close();
SQLConn.Open();
}
catch
{
throw new Exception("Database Connection Error");
}
}
}
}