gpt4 book ai didi

c# - MySQL 中 INNER JOIN 的语法错误

转载 作者:行者123 更新时间:2023-11-29 05:33:18 24 4
gpt4 key购买 nike

尝试从 MySqL 服务器内部连接数据库时出现错误。

我收到这个错误:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'lines INNER JOIN snippets ON snippets.id = lines.snippetid_fk WHERE lines.snippe' at line 1

我在 ASP.Net C# 中编码。

这是我给出错误的函数:

MySqlConnection conn = new MySqlConnection();

string mysql = "Server=***;Database=***;User=***;pwd=***";
conn.ConnectionString = mysql;

MySqlCommand cmd = new MySqlCommand();
cmd.CommandText = "SELECT * FROM lines " +
"INNER JOIN snippets ON snippets.id = lines.snippetid_fk " +
"WHERE lines.snippetid_fk = 1";
cmd.Connection = conn;

DataTable dt = new DataTable();
MySqlDataAdapter adapter = new MySqlDataAdapter(cmd);

adapter.Fill(dt);

Repeater_codebank.DataSource = dt;
Repeater_codebank.DataBind();

最佳答案

根据文档,list of MySQL reserved words中.

要使您的查询有效,您必须在表名周围添加反引号:

cmd.CommandText = "SELECT * FROM `lines` " +
"INNER JOIN snippets ON snippets.id = lines.snippetid_fk " +
"WHERE `lines`.snippetid_fk = 1";

关于c# - MySQL 中 INNER JOIN 的语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12885713/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com