-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUserList.cs
55 lines (45 loc) · 1.58 KB
/
UserList.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MySql.Data.MySqlClient;
namespace dbCon2
{
class UserList
{
public List<User> GetAllUsers()
{
try
{
ConnectionSettings connectionSettings = new ConnectionSettings();
connectionSettings.ConnectionSet();
using (MySqlConnection connection = new MySqlConnection(ConnectionSettings.ConectionVal()))
{
List<User> Users = new List<User>();
MySqlCommand command = connection.CreateCommand();
command.CommandText = $"SELECT * FROM users;";
connection.Open();
MySqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
User user = new User
{
DefaultUser = false,
UserID = reader["User_ID"].ToString(),
UserNameDB = reader["User_Name"].ToString(),
UserRankDB = reader["User_Rank"].ToString()
};
Users.Add(user);
};
connection.Close();
return Users;
}
}
catch (Exception)
{
return null;
}
}
}
}