- Home /
SQLite Sort and or List Sort
I'm working on an android app in unity.(C#) I have an sqlite database using the SQLiter asset downloaded from the asset store.
It works fine, but prints out the data as entered. So if you delete something and put it back in, it places it at the very end rather than where it used to be. I've tried to have it sort, but neither way seems to be recognized.
public void ShowAllEquipment()
{
for(int i = 0; i< Equipment.Count; i++)
{
GameObject beObj = Instantiate(EquipmentPrefab);
BandEquipment tmpEquipment = Equipment[i];
beObj.GetComponent<EquipmentScript>().DisplayEquipment(tmpEquipment.EquipmentID, tmpEquipment.EquipmentDescription);
beObj.transform.SetParent(Displayparent);
}
Equipment.Sort(SortByEquipmentID); This gives an error that it doesn't know what SortByxxxx is.
}
public void GetAllEquipment()
{
Equipment.Clear();
mConnection.Open();
mSQLString = "SELECT * FROM " + SQL_TABLE_EQUIPMENT ORDER BY EquipmentID; Here it give me a red squiggle on ORDER BY
mCommand.CommandText = mSQLString;
mCommand.ExecuteNonQuery();
mReader = mCommand.ExecuteReader();
while (mReader.Read())
{
Equipment.Add(new Equipment(mReader.GetString(0),
mReader.GetString(1)));
Debug.Log(mReader.GetString(0) + mReader.GetString(1));
}
mReader.Close();
mConnection.Close();
}
What is the best way to do this?
Where does it need to be done?
Any suggestions?
Thanks all!
Answer by jgodfrey · Feb 20, 2016 at 09:51 PM
For starters, this...
mSQLString = "SELECT * FROM " + SQL_TABLE_EQUIPMENT ORDER BY EquipmentID;
Should be...
mSQLString = "SELECT * FROM " + SQL_TABLE_EQUIPMENT + " ORDER BY " + EquipmentID;
Since the "ORDER BY" clause is just a static portion of the final string - not a variable reference.
Ahh! Thanks! I thought it must be something to do with quotes.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Return List from Singleton 1 Answer
How to create endless board game path 2 Answers
How to alphabetically sort your List? 2 Answers