public static WordRecord InsertRecord(WordRecord newRecord) { try { string queryinsert = "INSERT INTO UrduWordRecords (Word, Diacritic, IPA, UPS) VALUES (" + "'" + newRecord.UrduWord + "', " + "'" + newRecord.DiacriticRep + "', " + "'" + newRecord.IpaRep + "', " + "'" + newRecord.UpsRep + "');"; command = new OleDbCommand(queryinsert, OpenConnection()); if (command.ExecuteNonQuery() >= 0) { string querylatest = "SELECT * FROM UrduWordRecords WHERE ID = (SELECT max(ID) FROM UrduWordRecords);"; table = new DataTable(); command = new OleDbCommand(querylatest, OpenConnection()); adapter = new OleDbDataAdapter(command); adapter.Fill(table); return(new WordRecord(Convert.ToInt32(table.Rows[0][0].ToString()), table.Rows[0][1].ToString(), table.Rows[0][2].ToString(), table.Rows[0][3].ToString(), table.Rows[0][4].ToString())); } return(new WordRecord(-1, "", "", "", "")); } catch (Exception) { throw; } finally { connection.Close(); } }
public static bool UpdateRecord(WordRecord updatedRecord) { try { if (Database.UpdateRecord(updatedRecord)) { if (caching) { UpdateCache(updatedRecord); } return(true); } return(false); } catch (Exception) { throw; } }
public static bool AddNewRecord(WordRecord newWordRecord) { try { WordRecord enteredRecord = Database.InsertRecord(newWordRecord); if (enteredRecord.Id > 0) { if (caching) { UpdateCache(enteredRecord); } return(true); } return(false); } catch (Exception) { throw; } }
public static bool UpdateRecord(WordRecord newRecord) { try { string queryupdate = "UPDATE UrduWordRecords SET Word = '" + newRecord.UrduWord + "', Diacritic = '" + newRecord.DiacriticRep + "', IPA = '" + newRecord.IpaRep + "', UPS = '" + newRecord.UpsRep + "' " + "WHERE ID = " + newRecord.Id + ";"; command = new OleDbCommand(queryupdate, OpenConnection()); if (command.ExecuteNonQuery() >= 0) { return(true); } return(false); } catch (Exception) { throw; } finally { connection.Close(); } }
private static void UpdateCache(WordRecord newRecord) { try { // if exists, then update it for (int i = 0; i < cacheRegister.Count; i++) { if (cacheRegister[i].Id == newRecord.Id) { cacheRegister[i] = newRecord; return; } } // otherwise, enter new record in cache register cacheRegister.Add(newRecord); } catch (Exception) { throw; } }