コード例 #1
0
        /// <summary>
        /// Set value from database for fields of the object
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="dre"></param>
        /// <param name="type"></param>
        public static void SetValueForObject(object obj, IDataReader dre, FieldInfo[] myFieldInfo)
        {
            for (int i = 0; i < myFieldInfo.Length; i++)
            {
                //get type of field
                Type   type      = myFieldInfo[i].FieldType;
                string paramName = myFieldInfo[i].Name;

                // convert value to DB value
                object value = DBConvert.ParseToDBValue(myFieldInfo[i].GetValue(obj));

                // if type is char
                if (type == typeof(System.Char))
                {
                    myFieldInfo[i].SetValue(obj, DBConvert.ParseDBToChar(dre, paramName));
                }
                // if type is string
                else if (type == typeof(System.String))
                {
                    myFieldInfo[i].SetValue(obj, DBConvert.ParseDBToString(dre, paramName));
                }
                // if type is smallint
                else if (type == typeof(System.Int16))
                {
                    myFieldInfo[i].SetValue(obj, DBConvert.ParseDBToSmallInt(dre, paramName));
                }
                // if type is int
                else if (type == typeof(System.Int32))
                {
                    myFieldInfo[i].SetValue(obj, DBConvert.ParseDBToInt(dre, paramName));
                }
                // if type is long
                else if (type == typeof(System.Int64))
                {
                    myFieldInfo[i].SetValue(obj, DBConvert.ParseDBToLong(dre, paramName));
                }
                // if type is decimal
                else if (type == typeof(System.Decimal))
                {
                    myFieldInfo[i].SetValue(obj, DBConvert.ParseDBToDecimal(dre, paramName));
                }
                // if type is double
                else if (type == typeof(System.Double))
                {
                    myFieldInfo[i].SetValue(obj, DBConvert.ParseDBToDouble(dre, paramName));
                }
                // if type is datetime
                else if (type == typeof(System.DateTime))
                {
                    myFieldInfo[i].SetValue(obj, DBConvert.ParseDBToDateTime(dre, paramName));
                }
            }
        }
コード例 #2
0
 /// <summary>
 /// Set value from database for fields of the object
 /// </summary>
 /// <param name="obj"></param>
 /// <param name="dre"></param>
 /// <param name="type"></param>
 private static void SetValue(object obj, PropertyInfo field, IDataReader dre)
 {
     // if type is char
     if (field.PropertyType == typeof(System.Char))
     {
         field.SetValue(obj, DBConvert.ParseDBToChar(dre, field.Name), null);
     }
     // if type is string
     else if (field.PropertyType == typeof(System.String))
     {
         field.SetValue(obj, DBConvert.ParseDBToString(dre, field.Name), null);
     }
     // if type is smallint
     else if (field.PropertyType == typeof(System.Int16))
     {
         field.SetValue(obj, DBConvert.ParseDBToSmallInt(dre, field.Name), null);
     }
     // if type is int
     else if (field.PropertyType == typeof(System.Int32))
     {
         field.SetValue(obj, DBConvert.ParseDBToInt(dre, field.Name), null);
     }
     // if type is long
     else if (field.PropertyType == typeof(System.Int64))
     {
         field.SetValue(obj, DBConvert.ParseDBToLong(dre, field.Name), null);
     }
     // if type is decimal
     else if (field.PropertyType == typeof(System.Decimal))
     {
         field.SetValue(obj, DBConvert.ParseDBToDecimal(dre, field.Name), null);
     }
     // if type is double
     else if (field.PropertyType == typeof(System.Double))
     {
         field.SetValue(obj, DBConvert.ParseDBToDouble(dre, field.Name), null);
     }
     // if type is datetime
     else if (field.PropertyType == typeof(System.DateTime))
     {
         field.SetValue(obj, DBConvert.ParseDBToDateTime(dre, field.Name), null);
     }
 }