public static object selectValue(string sql, string database) { List <List <object> > list = RTDB.lowSelectObs(sql, database); if (list.Count == 0) { return(null); } return(list[2][0]); }
public object select(string sql) { Type type = this.GetType(); List <List <object> > table = RTDB.lowSelectObs(sql, database); if (table.Count == 0) { return(null); } if (table.Count == 1) { var wtf = true; return(null); } List <string> names = new List <string>(); for (int i = 0; i < table[0].Count; ++i) { names.Add(table[0][i] as string); } FieldInfo[] fields = this.GetType().GetFields(); for (int i = 0; i < fields.Length; ++i) //foreach (FieldInfo prop in this.GetType().GetFields()) { FieldInfo prop = fields[i]; type = Nullable.GetUnderlyingType(prop.FieldType) ?? prop.FieldType; string name = prop.Name; int index = names.IndexOf(name); object value = table[2][index]; if (type.Name == "String") { if (value == null) { value = ""; } if (value.GetType().Name == "DBNull") { value = ""; } } if (type.Name == "Bool" || type.Name == "Boolean") { if (value == null) { value = false; } if (value.GetType().Name == "DBNull") { value = false; } if (value.ToString().Contains("1")) { value = true; } if (value.ToString().Contains("0")) { value = false; } } if (type.Name == "DateTime" || type.Name == "DateTime") { try { value = parseDateTime(value as string); } catch (Exception err) { value = new DateTime(1899, 1, 1); } } if (type.Name != value.GetType().Name) { var wtf = value.GetType().Name; } else { prop.SetValue(this, value); } } return(this); }