尝试从MySqL服务器加入内部联接数据库时出错。
我收到此错误:
您的SQL语法有错误;查看与您的MySQL服务器版本对应的手册,以获得正确的语法,以便在“行INNER JOIN片段”附近使用ON snippets.id = lines.snippetid_fk WHERE lines.snippe'在第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();
答案 0 :(得分:3)
根据文档,lines
位于cmd.CommandText = "SELECT * FROM `lines` " +
"INNER JOIN snippets ON snippets.id = lines.snippetid_fk " +
"WHERE `lines`.snippetid_fk = 1";
。
要查询您的查询,您必须在表名周围添加反引号:
{{1}}