mysql语法错误

qzwqbdag  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(456)

下面是我测试过的sql查询

Select 
    data_info.user_id, data_info.type_id, data_info.specific_title,
    data_info.content, life_area.type_id, life_area.type_id
From
    data_info 
Left Join
    life_area On data_info.type_id = life_area.id
Where 
    data_info.user_id = '0001'

现在我正在尝试将工作sql转换为asp.net MySqlCommand ,但它无法工作并显示语法错误

MySqlCommand cmd = new MySqlCommand(
    "Select data_info.user_id,data_info.type_id,data_info.specific_title,data_info.content,"+
    "life_area.type_id,life_area.type_id" +
    "FROM data_info LEFT JOIN life_area ON data_info.type_id = life_area.id" +
    "Where data_info.user_id='0001'" , conn);
rkkpypqq

rkkpypqq1#

你把这些弦组合在一起,在关键区域没有空格,例如。 life_area.type_id' + 'FROM data_info' 给你 life_area.type_idFROM data_info ; 这使您的sql无效。使用 @ (verbatim string)表示回车的字符串可能是最好的解决方案:

MySqlCommand cmd = new MySqlCommand(
    @"Select data_info.user_id,data_info.type_id,data_info.specific_title,data_info.content,
    life_area.type_id,life_area.type_id
    FROM data_info LEFT JOIN life_area ON data_info.type_id = life_area.id 
    Where data_info.user_id='0001'" , conn);

相关问题