Plazza Sele Plazza Sele - 6 months ago 17
SQL Question

Error on [order by] in SQL Server CE

I have a

.sdf
database file with a table
tblOrderLine
. When I use
order by
I get an error, when I remove the
order by
it is working fine. Any help would be appreciated.

The error:


SqlCeException was caught There was an error parsing the query.

[Token line number = 1,Token line offset = 80,Token in error = order by]


My SQL code:

SqlCeCommand com = new SqlCeCommand("(Select LineID, OrderID, ItemName, Code from [tblOrderLine] where Code=@code [order by] tblOrderLine.LineID desc)", con);
com.Parameters.Add("@code", SqlDbType.NVarChar).Value = code;

Answer

You should not use the Square brackets for keywords other than database objects.

Remove [] for the keyword order by.

Update

SqlCeCommand com = new SqlCeCommand(@"Select LineID, OrderID, ItemName, Code from [tblOrderLine] where Code=@code order by tblOrderLine.LineID desc", con);

Try this