I keep getting an Error 1064
with this Text:
An unhandled exception of type 'MySql.Data.MySqlClient.MySqlException' occurred in MySql.Data.dll Additional information: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '[Tisch 1]' at line 1
This is my Coding:
using MySql.Data.MySqlClient;
namespace Tischreservierung1000
{
public partial class Reservierung : Form
{
private MySqlConnection con;
private MySqlCommand sql;
private MySqlConnection connection = new MySqlConnection();
public Reservierung()
{
InitializeComponent();
String connect = "Server=localhost;Port=3306;Database=tischreservierer;uid=Tischreservierer;";
con = new MySqlConnection(connect);
//Prüfe ob Tisch 1 schon reserviert ist
con.Open();
sql = con.CreateCommand();
sql.CommandText = "select * from [Tisch 1];";
MySqlDataReader reader = sql.ExecuteReader();
while (reader.Read())
{
if (reader.GetString(3) == "Reserviert") { T1Res = false; } else { }
if (T1Res == false) { T1R.BackgroundImage = null ; T1R.BackColor = Color.DarkRed; T1S1R.BackColor = Color.DarkRed; if (reader.GetInt32(2) == 2) { T1S2R.BackColor = Color.DarkRed; } } else { }
}
}
//Prüfe ob Tisch 2 schon reserviert ist
sql = con.CreateCommand();
sql.CommandText = "select * from `Tisch 2`;";
reader = sql.ExecuteReader();
while (reader.Read())
{
if (reader.GetString(3) == "Reserviert") { T2Res = false; } else { }
if (T2Res == false) { T2R.BackgroundImage = null; T2R.BackColor = Color.DarkRed; T2S1R.BackColor = Color.DarkRed; if (reader.GetInt32(2) == 2) { T2S2R.BackColor = Color.DarkRed; } } else { }
}
}
The error shows up in this line:
MySqlDataReader reader = sql.ExecuteReader();
Why is he trying to get a Connection to MariaDB? I used the Access Database before and it worked this way.
It helped with the Backticks. But now im getting following Error: There is already an open DataReader associated with this Connection which must be closed first.
Error Code Line @ "Tisch 2":
reader = sql.ExecuteReader();
(Ive added it above)
Thanks for your help
The delimiter you are using is the SQL delimiter, not the MySQL delimiter. Use ` instead of [ and ].