/// <summary> /// Adds a new user account. /// </summary> /// <param name="username">Username.</param> /// <param name="password">Password.</param> public void AddAccount(string username, string password) { try { using (var conn = new SQLite.SQLiteConnection (dbPath)) { var cmd = new SQLite.SQLiteCommand (conn); cmd.CommandText = "insert into accounts(username,password) values('" + username + "','" + password + "')"; cmd.ExecuteNonQuery(); } } catch (Exception ex) { Console.WriteLine ("Error:" + ex.Message); } }
//Function for executing qurey to the database, pass in query string public void runQuery(string query) { try { using (var conn = new SQLite.SQLiteConnection(dbPath)) { var cmd = new SQLite.SQLiteCommand(conn); cmd.CommandText = query; var rowcount = cmd.ExecuteNonQuery(); } } catch (Exception e) { Console.WriteLine("Error:" + e.Message); } }
public void editNote(string title, string body, string id) { try { using (var conn = new SQLite.SQLiteConnection(dbPath)) //----------------------------------------------------------Prepares connection to database { var cmd = new SQLite.SQLiteCommand(conn); //-------------------------------------------------------------------Prepares communication with database string sql = "UPDATE NOTES_TBL SET Title = '" + title + "', Body = '" + body + "' WHERE NoteID = " + id; //---SQLite query to pass back cmd.CommandText = sql; //--------------------------------------------------------------------------------------Passes query to db cmd.ExecuteNonQuery(); //--------------------------------------------------------------------------------------Writes information to db ViewAll(); //--------------------------------------------------------------------------------------------------Gets a list of the notes and passes it in } } catch (Exception e) { Console.WriteLine("Error: " + e.Message); //-----------------------------------------------------------------------Write error in english to output } }
public void writeNote(string title, string dt, string body) { try { using (var conn = new SQLite.SQLiteConnection(dbPath)) //--------------------------------------------------------------Prepares connection to database { var cmd = new SQLite.SQLiteCommand(conn); //-----------------------------------------------------------------------Prepares communication with database string sql = "Insert into NOTES_TBL (Title, Body, Dt) values ('" + title + "','" + body + "', '" + dt + "')"; //---SQLite query to pass back cmd.CommandText = sql; //------------------------------------------------------------------------------------------Passes query to db cmd.ExecuteNonQuery(); //------------------------------------------------------------------------------------------Writes information to db ViewAll(); //------------------------------------------------------------------------------------------------------Gets a list of the notes and passes it in } } catch (Exception e) { Console.WriteLine("Error: " + e.Message); //---------------------------------------------------------------------------Write error in english to output } }
/// <summary> /// Sets the new highscore. /// </summary> /// <param name="username">Username.</param> /// <param name="score">Score.</param> public void setNewHighscore(string username, int score) { try { using (var conn = new SQLite.SQLiteConnection (dbPath)) { var cmd = new SQLite.SQLiteCommand (conn); cmd.CommandText = "insert into highscores(username,score) values('" + username + "','" + score + "')"; cmd.ExecuteNonQuery(); } } catch (Exception ex) { Console.WriteLine ("Error:" + ex.Message); } }