How can I sort data in sqlite in c#? My code:
static class Rank
{
private static SQLiteConnection _sqlite_conn;
private static SQLiteCommand _sqlite_cmd;
private static SQLiteDataReader _sqlite_datareader;
static Rank()
{
// Create a new database connection
_sqlite_conn = new SQLiteConnection("Data Source=Highscores.sqlite;Version=3;");
}
public static void SortDataBase()
{
_sqlite_conn.Open();
string sql = "SELECT * FROM 'Highscores' order by 'Time'";
_sqlite_cmd = new SQLiteCommand(sql, _sqlite_conn);
_sqlite_conn.Close();
}
}
but this doesn't work. Could you help me ? Time is int value.
You can't sort the data in the database table itself, but you can sort it when you select it. So for example SELECT * FROM Highscores order by Time
should work but you have to actually execute your statement with _sqlite_cmd.ExecuteReader()
which returns a reader that can be used to iterate over the data. See this link: SQLite Command
TRY THIS,successfully sorted data based on the time in ascending order.
string selectsql = "SELECT filename,size,time FROM googledrive ORDER BY time ASC";
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.