public HighScoreEntry[] GetHighScore() { List<HighScoreEntry> localList = new List<HighScoreEntry>(); string stm = "select * from HighScore order by Points desc"; try { con.Open(); using (SQLiteCommand cmd = new SQLiteCommand(stm, con)) { using (SQLiteDataReader rdr = cmd.ExecuteReader()) { while (rdr.Read()) { HighScoreEntry localEntry = new HighScoreEntry(); localEntry.Name = rdr["name"].ToString(); localEntry.Points = Convert.ToInt32(rdr["points"]); localList.Add(localEntry); } } } }catch(SQLiteException e) { throw new HighScoreException(e.Message); } return localList.ToArray(); }
public void AddToHighScore(HighScoreEntry highScoreEntry) { try { con.Open(); string stm = "Insert into HighScore (Name, Points) values (@Name,@Points) "; using (SQLiteCommand cmd = new SQLiteCommand(stm, con)) { cmd.CommandType = CommandType.Text; cmd.Parameters.AddWithValue("Name", highScoreEntry.Name); cmd.Parameters.AddWithValue("Points", highScoreEntry.Points); cmd.ExecuteNonQuery(); } con.Close(); }catch (SQLiteException e) { throw new HighScoreException(e.Message); } }