Answer the question
In order to leave comments, you need to log in
How to get rowid number from Sqlite?
I am writing a desktop application in C# + WPF
, there is a table in the SQLite database, there is an ID
field in the ID field there is the number of each record, by which I manipulate records in the database
I created a method that receives all rows with IDs, and inserts all these numbers into combobox. When you click on the combobox, it displays all the table IDs.
The problem is that if I delete any record from the table somewhere in the middle, then when creating a new record, the ID field will have a number out of order, but the one that will become after deletion, but in the combobox I need the numbers of all records in order.
How can I get all id numbers not by the ID field but by rowid? because there they all go in order
Screenshot of my SQlite table:
Method for getting all id:
public void GetIdFromDatabase(ComboBox comboBox, string category)
{
SetConnection();
sqlCon.Open();
string selectQuery = "SELECT ID FROM" + " " + category;
sqlCommand = new SQLiteCommand(selectQuery, sqlCon);
try
{
SQLiteDataReader sqReader = sqlCommand.ExecuteReader();
// Always call Read before accessing data.
while (sqReader.Read())
{
string questions = sqReader["ID"].ToString();
comboBox.Items.Add(questions);
}
// always call Close when done reading.
sqReader.Close();
}
finally
{
sqlCon.Close();
}
}
Answer the question
In order to leave comments, you need to log in
Solution found!
after I do data manipulation in sqlite, I run a method that will make the following query:
this query takes all the values of the ID field on all rows and assigns them values from the rowid, this is a special field that is assigned by default and stores all row numbers sequentially.
Only if I need to delete a record, before this request, I still need to make a request
, I'm happy with the result)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question