-
Notifications
You must be signed in to change notification settings - Fork 0
/
DB_Function.cs
61 lines (61 loc) · 1.93 KB
/
DB_Function.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MySql.Data.MySqlClient;
using System.Data;
using System.Windows.Forms;
namespace Hostel_Managment_System
{
internal class DB_Function
{
protected MySqlConnection GetConnection()
{
MySqlConnection conn = new MySqlConnection
{
ConnectionString = "data source = MySQL Community Server - GPL;integrated security = True;server=localhost;user=root;database=Hostel;port=3306;password=jinu0292"
};
return conn;
}
public DataSet GetData(string query)
{
MySqlConnection conn = GetConnection();
MySqlCommand cmd = new MySqlCommand
{
Connection = conn,
CommandText = query
};
MySqlDataAdapter da = new MySqlDataAdapter(cmd);
DataSet dataSet = new DataSet();
da.Fill(dataSet);
return dataSet;
}
public void SetData(string query, string msg)
{
MySqlConnection conn = GetConnection();
MySqlCommand cmd = new MySqlCommand
{
Connection = conn
};
conn.Open();
cmd.CommandText = query;
cmd.ExecuteNonQuery();
conn.Close();
MessageBox.Show(msg, "Information", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
public void SetData(string query)
{
MySqlConnection conn = GetConnection();
MySqlCommand cmd = new MySqlCommand
{
Connection = conn
};
conn.Open();
cmd.CommandText = query;
cmd.ExecuteNonQuery();
conn.Close();
//MessageBox.Show(msg, "Information", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
}