Files
WIR-MACHEN-ALLE-ARM/Casino/Database.cs
T
2026-08-20 15:59:54 +02:00

61 lines
2.0 KiB
C#

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MySql.Data.MySqlClient;
namespace Casino
{
internal class Database
{
private string myConnectionString = "server=mysql.pb.bib.de;uid=pbg2h25ala;pwd=a7TP2aRv7Xdu;database=pbg2h25ala_Casino";
public ObservableCollection<User> SelectTask()
{
ObservableCollection<User> user = new ObservableCollection<User>();
try
{
MySql.Data.MySqlClient.MySqlConnection myConnection;
myConnection = new MySql.Data.MySqlClient.MySqlConnection(myConnectionString);
//open a connection
myConnection.Open();
// create a MySQL command and set the SQL statement with parameters
MySqlCommand myCommand = new MySqlCommand();
myCommand.Connection = myConnection;
myCommand.CommandText = @"SELECT * FROM Nutzer";
// myCommand.Parameters.AddWithValue("@code", "12");
// execute the command and read the results
using MySqlDataReader myReader = myCommand.ExecuteReader();
while (myReader.Read())
{
User u = new User(myReader.GetString("name"), myReader.GetInt32("age"), myReader.GetString("passwort"))
{
ID = myReader.GetString("id"),
Name = myReader.GetString("name"),
Alter = myReader.GetInt32("age"),
Passwort = myReader.GetString("passwort"),
Geld = myReader.GetInt32("geld")
};
user.Add(u);
}
myConnection.Close();
}
catch (MySql.Data.MySqlClient.MySqlException ex)
{
Console.WriteLine(ex.Message);
}
return user;
}
}
}