简体   繁体   中英

Server Error in '/' Application. in c#.net

Am passing MYSQL query in C#.Net and am always getting the same error.

My Query is

    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();

Please correct my syntax.

My Error is

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 'adm_advt_question adq ON ad.Q_ID = adq.nID INNERJOIN login l ON adq.Buserid = l.' at line 1

Try INNER JOIN instead of 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");

You should consider using PreparedStatements to avoid sql injection .(for the parameter username )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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