Jump to content

Exception With Sql Statment In Vb (Asp.net)


Geee

Recommended Posts

Hello I have this SQL Statement: de.SqlStatement = "SELECT A.Name, A.Catagory , COUNT(Patient_ID) AS PNO FROM PatientApplyToAssociation P INNER JOIN Association A on A.Association_ID = P.Association_ID WHERE A.Catagory='" & "health" & " '" & "' GROUP BY A.Name '" with this Exception: System.Data.SqlClient.SqlException was unhandled by user code class="16" ErrorCode=-2146232060 LineNumber=1 Message=Column 'Association.Name' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause. I had this exception when I added the where clause, It seems that the compiler cant see the Group By Section , because of the quotation ending before it, I tried to write it like this: de.SqlStatement = "SELECT A.Name, A.Catagory , COUNT(Patient_ID) AS PNO FROM PatientApplyToAssociation P INNER JOIN Association A on A.Association_ID = P.Association_ID WHERE A.Catagory='" & "health" & "' GROUP BY A.Name '" & " '" But it was an Incorrect syntax near ' '. p.s. I selected A.Catagory because I needed it in the WHERE clause, I need the category to be "health"Any ideas ? Please Help me..Thank you

Link to comment
Share on other sites

You don't need to break up the string like that if you're just using literal strings for everything.

de.SqlStatement = "SELECT A.Name, A.Catagory , COUNT(Patient_ID) AS PNO FROM PatientApplyToAssociation P INNER JOIN Association A on A.Association_ID = P.Association_ID WHERE A.Catagory='health' GROUP BY A.Name"

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...