/// <summary> /// 直接插入数据库操作并获取ID /// </summary> /// <param name="o"></param> /// <param name="tableName"></param> /// <returns></returns> public int AddToDbForId(object o, string tableName) { SqlObject s = new SqlObject(SqlObjectType.Insert, tableName, DBTYPE.MySql); foreach (System.Reflection.PropertyInfo p in o.GetType().GetProperties()) { if (p.GetValue(o, null) != null && p.GetValue(o, null).ToString().Length > 0) { if (p.Name != "id" && p.Name != "helper") { s.AddField(p.Name, p.GetValue(o, null), GetSqlFieldType(p.PropertyType.Name)); } } } return(helper.InsertToDb(s.ToString())); }
/// <summary> /// 修改数据库 /// </summary> /// <param name="o"></param> /// <param name="tableName"></param> /// <param name="where"></param> /// <returns></returns> public bool UpdateDb(object o, string tableName, string where) { SqlObject s = new SqlObject(SqlObjectType.Update, tableName, DBTYPE.MySql); foreach (System.Reflection.PropertyInfo p in o.GetType().GetProperties()) { if (p.GetValue(o, null) != null) { if (p.Name != "id" && p.Name != "helper") { s.AddField(p.Name, p.GetValue(o, null), GetSqlFieldType(p.PropertyType.Name)); } } } s.Where = where; return(helper.ExecuteSqlNoResult(s.ToString())); }