56 lines
2.0 KiB
C#
56 lines
2.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
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<Task> SelectTask()
|
|
{
|
|
ObservableCollection<Task> taskList = new ObservableCollection<Task>();
|
|
|
|
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 task";
|
|
// myCommand.Parameters.AddWithValue("@code", "12");
|
|
|
|
// execute the command and read the results
|
|
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();
|
|
}
|
|
catch (MySql.Data.MySqlClient.MySqlException ex)
|
|
{
|
|
Console.WriteLine(ex.Message);
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|