public void SaveToDatabase(MySqlConnection con) { ValidateDataBeforeSave(); if (ID == 0) { // Insert string strCommandText = InsertCommand; using (MySqlCommand cmd = new MySqlCommand(strCommandText, con)) { using (MySqlDataReader reader = cmd.ExecuteReader()) { if (!reader.Read()) { throw new Exception(@"Insert: 'SELECT LAST_INSERT_ID()' seems to have failed"); } ID = reader.GetUInt32(0); } } AdditionalInsertCode(con); } else { // Update MySqlUtils.ExecuteNonQuery(con, UpdateCommand); AdditionalUpdateCode(con); } }
private void DeleteFromDatabase(MySqlConnection con) { // Assert(FieldID > 0); string strCommandText = string.Format(@"DELETE FROM TargetFormFields WHERE FieldID={0};", FieldID); MySqlUtils.ExecuteNonQuery(con, strCommandText); }
private void UpdateInDatabase(MySqlConnection con) { // Assert(FieldID > 0); string strCommandText = string.Format(@"UPDATE TargetFormFields SET TargetID={0}, FieldName={1}, FieldValue={2} WHERE FieldID={3};", TargetID, MySqlUtils.RawStringToDatabaseString(FieldName), MySqlUtils.RawStringToDatabaseString(FieldValue), FieldID); MySqlUtils.ExecuteNonQuery(con, strCommandText); }
public void DeleteFromDatabase(MySqlConnection con) { if (ID == 0) { // This object's data has not yet been inserted into the database table; there is nothing to delete. return; } AdditionalDeleteCode(con); MySqlUtils.ExecuteNonQuery(con, DeleteCommand); }
public void DeleteFromDatabase(MySqlConnection con, UInt32 unTargetID) { string strCommandText = string.Format(@"DELETE FROM TargetFormFields WHERE TargetID={0};", unTargetID); MySqlUtils.ExecuteNonQuery(con, strCommandText); }
public void UpdateLastTargetLogID(uint unLogID, MySqlConnection con) { LastTargetLogID = unLogID; MySqlUtils.ExecuteNonQuery(con, UpdateLastTargetLogIDCommand); }
// **** Methods **** public void UpdateLastMonitoredAt(DateTime dt, MySqlConnection con) { LastMonitoredAt = dt; MySqlUtils.ExecuteNonQuery(con, UpdateLastMonitoredAtCommand); }