-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram_DataBase.cs
More file actions
50 lines (47 loc) · 1.58 KB
/
Copy pathProgram_DataBase.cs
File metadata and controls
50 lines (47 loc) · 1.58 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
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql;
using MySql.Data;
using MySql.Data.MySqlClient;
namespace DormitoryManagment
{
internal static class DataBase
{
internal static DataTable GetDataSource(string sql)
{
DataTable dt = new DataTable();
try
{
MySqlConnection tableConn = new MySqlConnection(
"server=103.200.22.212;user=luanapco_admin;database=luanapco_Database;port=3306;password=AWb@8AzpaqzH9Ev");
Program.adapter = new MySqlDataAdapter(sql, tableConn);
Program.adapter.Fill(dt);
}
catch (Exception e)
{
MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
return dt;
}
internal static void SaveChanges(DataTable dataTable)
{
try
{
Program.adapter.UpdateCommand = new MySqlCommandBuilder(Program.adapter).GetUpdateCommand();
Program.adapter.Update(dataTable);
MessageBox.Show("Save changes successfully", "Update successfully", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (System.Exception e)
{
MessageBox.Show(e.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}