-
Notifications
You must be signed in to change notification settings - Fork 0
/
connect.cs
95 lines (68 loc) · 2.18 KB
/
connect.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.SqlClient;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using System.Data;
namespace Aplikacja
{
public class connect : IObserwowany
{
public bool con { get; set; }
public connect()
{
}
public string dane2 { get; set; }
public DataTable dt { get; private set; }
private List<IObserwator> _listaObserwatorow = new List<IObserwator>();
public void dodajObserwatora(IObserwator o)
{
_listaObserwatorow.Add(o);
}
public void usunObserwator(IObserwator o)
{
_listaObserwatorow.Remove(o);
}
public void powiadomObserwatorow()
{
foreach (var item in _listaObserwatorow)
{
item.aktualizacjaDanych();
}
}
public void pobierzdane(string sql)
{
// f.dane(dane2);
string mojePolaczenie2 =
"SERVER=mysql11.mydevil.net;" +
"DATABASE=m1756_aplikacja;" +
"UID=m1756_baid2;" +
"PASSWORD=30Projektto;";
MySqlConnection connection = new MySqlConnection(mojePolaczenie2);
try
{
//otwórz połączenie z bazą danych
connection.Open();
//wykonaj polecenie języka SQL na danych połączeniu
using (MySqlCommand cmdSel = new MySqlCommand(sql, connection))
{
dt = new DataTable();
//Pobierz dane i zapisz w strukturze DataTable
MySqlDataAdapter da = new MySqlDataAdapter(cmdSel);
da.Fill(dt);
//wpisz dane do kontrolki DATAGRID
con = true;
}
}
//Jeżeli wystąpi wyjątek wyrzuć go i pokaż informacje
catch (MySql.Data.MySqlClient.MySqlException ex)
{
con = false; }
//Zamknij połączenie po wyświetleniu danych
connection.Close();
}
}
}