public void Update(Room roomObj, int id) { string sqlStr = string.Format( "Update Room Set R_PetName = '{0}', R_SeatsNumber = '{1}', R_StandsNumber = '{2}', R_Storey = '{3}', R_HasProjector = '{4}', R_Description = '{5}' Where R_ID = '{6}'", roomObj.PetName, roomObj.SeatsNumber, roomObj.StandsNumber, roomObj.Storey, roomObj.HasProjector, roomObj.Description, id); using (SqlCommand cmd = new SqlCommand(sqlStr, this.SqlCn)) { try { cmd.ExecuteNonQuery(); } catch (Exception ex) { Exception error = new Exception("Couldn't update the Room! " + ex.Message, ex); throw error; } } }
// room public void Insert(Room roomObj, int id) { string sqlStr = string.Format("Insert Into Room" + "(R_PetName, R_SeatsNumber, R_StandsNumber, R_Storey, R_HasProjector, R_Description, R_MP_ID, R_AddedTime) Values" + "('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}')" , roomObj.PetName, roomObj.SeatsNumber, roomObj.StandsNumber, roomObj.Storey, roomObj.HasProjector, roomObj.Description, id, DateTime.Now); // execute sql statement and insert roomObj data using (SqlCommand cmd = new SqlCommand(sqlStr, SqlCn)) { try { cmd.ExecuteNonQuery(); } catch (SqlException ex) { Exception error = new Exception("Couldn't insert the Room! " + ex.Message, ex); throw error; } } }