Plazza Sele Plazza Sele - 1 year ago 114
SQL Question

Error on [order by] in SQL Server CE

I have a

database file with a table
. 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 Source

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

Remove [] for the keyword order by.


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

Try this

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download