public override IInfo GetRecord(SmartDB dbInstance, object Id) { string sQL_GET = this.SQL_GET; SqlParameter[] array = new SqlParameter[] { new SqlParameter(this.PARM_ID, SqlDbType.NVarChar) }; array[0].Value = Id; Model.NodeDTO bizObject = null; IInfo result; try { bool transactionControl = dbInstance.TransactionControl; SqlDataReader sqlDataReader; if (transactionControl) { sqlDataReader = SqlHelper.ExecuteReader(dbInstance.Transaction, CommandType.StoredProcedure, sQL_GET, array); } else { sqlDataReader = SqlHelper.ExecuteReader(SqlHelper.MyConnectionString, CommandType.StoredProcedure, sQL_GET, array); } bool hasRows = sqlDataReader.HasRows; if (hasRows) { sqlDataReader.Read(); this.SetInfo(out bizObject, sqlDataReader); result = new ReturnInfo { BizObject = bizObject, Code = ErrorEnum.NoError }; } else { result = new ReturnInfo(ErrorEnum.NoRecord, string.Format("No record found")); } } catch (Exception ex) { result = new ReturnInfo(ErrorEnum.DataException, ex.Message); } return(result); }
protected void SetInfo(out Model.NodeDTO info, SqlDataReader reader) { try { info = new Model.NodeDTO(); info.City = CastDBNull.To <string>(reader["City"], ""); info.DMZ = CastDBNull.To <string>(reader["DMZ"], ""); info.MacAddress = CastDBNull.To <string>(reader["MacAddress"], ""); info.SerialNumber = CastDBNull.To <string>(reader["SerialNumber"], ""); info.IsNew = false; info.IsDirty = true; } catch (Exception ex) { throw ex; } }