Datenbank verbindung eingerichtet

This commit is contained in:
2026-08-19 14:27:11 +02:00
parent aaa7bce19e
commit 32d51bd432
+4 -15
View File
@@ -11,9 +11,9 @@ namespace Casino
internal class Database internal class Database
{ {
private string myConnectionString = "server=mysql.pb.bib.de;uid=pbg2h25ala;pwd=a7TP2aRv7Xdu;database=pbg2h25ala_Casino"; private string myConnectionString = "server=mysql.pb.bib.de;uid=pbg2h25ala;pwd=a7TP2aRv7Xdu;database=pbg2h25ala_Casino";
public ObservableCollection<Task> SelectTask() public ObservableCollection<User> SelectTask()
{ {
ObservableCollection<Task> taskList = new ObservableCollection<Task>(); ObservableCollection<User> user = new ObservableCollection<User>();
try try
{ {
@@ -25,24 +25,12 @@ namespace Casino
// create a MySQL command and set the SQL statement with parameters // create a MySQL command and set the SQL statement with parameters
MySqlCommand myCommand = new MySqlCommand(); MySqlCommand myCommand = new MySqlCommand();
myCommand.Connection = myConnection; myCommand.Connection = myConnection;
myCommand.CommandText = @"SELECT * FROM task"; myCommand.CommandText = @"SELECT * FROM Nutzer";
// myCommand.Parameters.AddWithValue("@code", "12"); // myCommand.Parameters.AddWithValue("@code", "12");
// execute the command and read the results // execute the command and read the results
using MySqlDataReader myReader = myCommand.ExecuteReader(); using MySqlDataReader myReader = myCommand.ExecuteReader();
while (myReader.Read())
{
/*int id = myReader.GetInt32("id");
int priority = myReader.GetInt32("priority");
string title = myReader.GetString("title");
double expense = myReader.GetDouble("expense");
bool done = myReader.GetBoolean("done");
Task t1 = new Task(id, priority, title, expense, done);
taskList.Add(t1);
Console.WriteLine($"ID: {id}, Priority: {priority}, Title: {title}, Expense: {expense}, Done: {done}");*/
}
myConnection.Close(); myConnection.Close();
} }
catch (MySql.Data.MySqlClient.MySqlException ex) catch (MySql.Data.MySqlClient.MySqlException ex)
@@ -50,6 +38,7 @@ namespace Casino
Console.WriteLine(ex.Message); Console.WriteLine(ex.Message);
} }
return user;
} }
} }
} }