简体   繁体   中英

Error while executing sql join query from c# ADO.net

I am trying to execute a simple SQL query from c# using ADO.net adapter.

Query access data from two tables using join.

Below is my code

newRequest=getrequest.selectQuery("select A.associateID, A.name, A.role, A.Salt FROM associate A INNER JOIN UserStatus UA ON UA.statusID=A.status" +
             "WHERE A.coordinatorID='"+cID+"' AND UA.statusName='WAITING FOR APPROVAL'");

con.Open();               
SqlDataAdapter sd = new SqlDataAdapter(query, con);
sd.Fill(ds);

I get error on execution:

Incorrect syntax near 'A'

Try below code:

newRequest=getrequest.selectQuery("select A.associateID, A.name, A.role, A.Salt FROM associate A " +
"INNER JOIN UserStatus UA ON UA.statusID=A.status "
"WHERE A.coordinatorID='" + cID + "' "
"AND UA.statusName='WAITING FOR APPROVAL'");

con.Open();               
SqlDataAdapter sd = new SqlDataAdapter(query, con);
sd.Fill(ds);

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