我正在C#.Net中传递MYSQL查询,并且总是遇到相同的错误。
我的查询是
topCustomers.DataSource = GetData("SELECT l.Username , Sum( ad.Amt ) AS Amount ,ad.UserDate FROM adm_advt_answer ad" +
"JOIN adm_advt_question adq ON ad.Q_ID = adq.nID" +
" INNERJOIN login l ON adq.Buserid = l.Buserid WHERE adq.Buserid = '" + username + "' AND adq.Active='Y' AND date( ad.UserDate ) = '2014-02-20'" +
" GROUP BY UserId");
topCustomers.DataBind();
请更正我的语法。
我的错误是
您的SQL语法有误;查看与您的MySQL服务器版本相对应的手册,以获取正确的语法,以在“ adm_advt_question adq ON ad.Q_ID = adq.nID INNERJOIN登录l ON adq.Buserid = l”附近使用。在第1行
最佳答案
尝试使用INNER JOIN
代替INNERJOIN
。
topCustomers.DataSource = GetData("SELECT l.Username , Sum( ad.Amt ) AS Amount
,ad.UserDate FROM adm_advt_answer ad " +//Notice the space at ending
"JOIN adm_advt_question adq ON ad.Q_ID = adq.nID" +
" INNER JOIN login l ON adq.Buserid = l.Buserid WHERE adq.Buserid = '" + username + "' AND
adq.Active='Y' AND date( ad.UserDate ) = '2014-02-20'" +
" GROUP BY UserId");
您应该考虑使用
PreparedStatements
来避免sql injection
。(对于参数username
)