简体   繁体   English

带有 xampp 的 C# 中的 MySql 错误 1064

[英]MySql Error 1064 in C# with xampp

I keep getting an Error 1064 with this Text:我不断收到带有此文本的Error 1064

An unhandled exception of type 'MySql.Data.MySqlClient.MySqlException' occurred in MySql.Data.dll Additional information: You have an error in your SQL syntax; MySql.Data.dll 中发生类型为“MySql.Data.MySqlClient.MySqlException”的未处理异常附加信息:您的 SQL 语法有错误; check the manual that corresponds to your MariaDB server version for the right syntax to use near '[Tisch 1]' at line 1检查与您的 MariaDB 服务器版本相对应的手册,了解在第 1 行的“[Tisch 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?他为什么要尝试连接到 MariaDB? I used the Access Database before and it worked this way.我以前使用过 Access 数据库,它是这样工作的。

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.但是现在我收到以下错误:已经有一个与此连接关联的打开的 DataReader,必须先关闭它。

Error Code Line @ "Tisch 2":错误代码行@“Tisch 2”:

reader = sql.ExecuteReader();读者 = sql.ExecuteReader();

(Ive added it above) (我已经在上面添加了)

Thanks for your help谢谢你的帮助

The delimiter you are using is the SQL delimiter, not the MySQL delimiter.您使用的分隔符是 SQL 分隔符,而不是 MySQL 分隔符。 Use ` instead of [ and ].使用 ` 代替 [ 和 ]。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM