Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
hi
I have a trouble in inserting data to sqlite db .when am inserting data to table it is automatically sorting in ascending order.I need to disable that one.please help

Thanks

What I have tried:

I have tried to change db's collation in code but still not working
Posted
Updated 4-Apr-16 5:18am
Comments
Sergey Alexandrovich Kryukov 5-Apr-16 0:10am    
Such concept as "disable" does not exist.
Your misconception is: you implicitly assume that there is some "natural" order, which is fundamental relative to any particular sorting, say, in the order of writing. But, in strict SQL sense, such order does not exist at all, this is something undefined. Wrong question.
—SA
priyadarshini tv 11-Apr-16 6:26am    
I got the solution from below answer

Thanks

1 solution

Unless you specify an order with an ORDER BY clause in your SELECT statement, the system is at liberty to return rows in any order it wants. Normally, this equates to "first in, first out" sequence, so your latest inserts will be last - but that isn't guaranteed and you can get different results with two identical SELECT statements (this is less likely with single user systems like SqLite than multiuser like SQL Server, but it should be considered in your design).

If you want a different order, then you have to specifically ask for it with an ORDER BY clause:
SQL
SELECT <my list of columns> 
FROM MyTable 
WHERE <my condition>
ORDER BY <my list of columns to sort by> <ASC or DESC for direction>

For example:
SQL
SELECT UserID, UserName FROM MyTable ORDER BY BirthDate DESC
 
Share this answer
 
Comments
priyadarshini tv 11-Apr-16 6:25am    
Hi OriginalGriff

Thanks for the solution.This is not what i expected to do.But your solution helped me in some other way to populate my data.Thanks for understanding my question
OriginalGriff 11-Apr-16 7:07am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900