コード例 #1
0
    /// <summary>
    /// Saves the player stats three times using a SQL statement. The calls are made inside of a transaction
    /// by using BeginTransaction and Commit. Transactions vastly reduce the amount of time it takes
    /// to save multiple records.
    /// </summary>
    /// <param name='playerName'>
    /// Player name.
    /// </param>
    /// <param name='totalKills'>
    /// Total kills.
    /// </param>
    /// <param name='points'>
    /// Points.
    /// </param>
    private void SavePlayerStats_QueryThreeTimes(string playerName, int totalKills, int points)
    {
        // set up our insert SQL statement with ? parameters
        string sql = "INSERT INTO PlayerStats (PlayerName, TotalKills, Points) VALUES (?, ?, ?)";

        // start a transaction
        dbManager.BeginTransaction();

        // execute the SQL statement three times
        dbManager.Execute(sql, playerName, totalKills, points);
        dbManager.Execute(sql, playerName, totalKills, points);
        dbManager.Execute(sql, playerName, totalKills, points);

        // commit our transaction to the database
        dbManager.Commit();
    }