DataAccessLibrary/DataAccess.cs
/// <summary>
/// Return scores from the database as list of Score objects in descending order
/// Example code: DataAccess.GetData()
/// </summary>
/// <param name="rows">Amount of rows to return, when 0 or nothing given return all rows</param>
/// <returns></returns>
Return scores from the database as list of Score objects in descending order
Example code: DataAccess.GetData()
Return scores from the database as list of Score objects in descending order Example code : DataAccess . GetData ()
public static List<Score> GetData(int rows = 0)
        {
            List<Score> entries = new List<Score>();
            string dbpath = Path.Combine(ApplicationData.Current.LocalFolder.Path, "database.db");
            using (SqliteConnection db =
                new SqliteConnection($"Filename={dbpath}"))
            {
                db.Open();
                SqliteCommand selectCommand;
                if (rows == 0)
                {
                    selectCommand = new SqliteCommand
                        ("SELECT Teamname1, Teamname2, Teamscore1, Teamscore2 from Scores ORDER BY ID DESC", db);
                }
                else
                {
                    selectCommand = new SqliteCommand
                        ("SELECT Teamname1, Teamname2, Teamscore1, Teamscore2 from Scores ORDER BY ID DESC LIMIT " + rows, db);
                }
                SqliteDataReader query = selectCommand.ExecuteReader();
                while (query.Read())
                {
                    entries.Add(new Score(query.GetString(0), query.GetString(1), query.GetInt32(2), query.GetInt32(3)));
                }
                db.Close();
            }
            return entries;
        }
public static List < Score > GetData ( int rows = 0 ) { List < Score > entries = new List < Score > ( ) ; string dbpath = Path . Combine ( ApplicationData . Current . LocalFolder . Path , " " ) ; using ( SqliteConnection db = new SqliteConnection ( $" Filename= { dbpath } " ) ) { db . Open ( ) ; SqliteCommand selectCommand ; if ( rows == 0 ) { selectCommand = new SqliteCommand ( " " , db ) ; } else { selectCommand = new SqliteCommand ( " " + rows , db ) ; } SqliteDataReader query = selectCommand . ExecuteReader ( ) ; while ( query . Read ( ) ) { entries . Add ( new Score ( query . GetString ( 0 ) , query . GetString ( 1 ) , query . GetInt32 ( 2 ) , query . GetInt32 ( 3 ) ) ) ; } db . Close ( ) ; } return entries ; }
Return scores from the database as list of Score objects in descending order
Example code: DataAccess.GetData()
Return scores from the database as list of Score objects in descending order Example code : DataAccess . GetData ()
None
rows
int
Amount of rows to return, when 0 or nothing given return all rows
Amount of rows to return when 0 or nothing given return all rows