public AccountSearch WriteRecordToDatabase(AccountSearch accountSearch) { //get the appropriate command bool isCreateCommand = false; SqlCommand writeCommand = null; if (accountSearch.ID <= 0) { //get the insert command writeCommand = base.commandInsert(accountSearch, constructSearchMemberList(accountSearch)); //add the search class-specific parameters writeCommand.Parameters.AddRange(constructWriteParameters(accountSearch)); isCreateCommand = true; //execute the insert command base._sqlController.ExecuteInsertCommand(writeCommand); } else { //get the update command writeCommand = base.commandUpdate(accountSearch, constructSearchMemberList(accountSearch)); //add the search class-specific parameters writeCommand.Parameters.AddRange(constructWriteParameters(accountSearch)); //execute the update command base._sqlController.ExecuteUpdateCommand(writeCommand); } int recordID = 0; if (isCreateCommand) { //get the returned ID from the output parameter object outputIDValue = getParameterValue(PARAM_ID, writeCommand.Parameters); if (outputIDValue == null) { //TODO: throw exception as the ID could not be found throw new ApplicationException("The output ID parameter could not be found."); } //conver the value to an integer recordID = (int)outputIDValue; accountSearch.ID = recordID; //put the ID onto the record } //return the updated object return accountSearch; }