/// <summary> /// 批量插入记录 /// </summary> /// <param name="h"></param> /// <returns></returns> public bool Insert <T>(List <T> listT) { try { if (listT == null || listT.Count == 0) { return(false); } List <string> listSql = new List <string>(); string sql = "select {0} from {1}"; IDbParameters param = AdoTemplate.CreateDbParameters(); Type type = typeof(T); PropertyInfo[] propertys = type.GetProperties(); TableMapAttribute attribute = TableMapAttribute.GetInstance(type); string tableName = attribute.TableName; string cols = ""; foreach (PropertyInfo pi in propertys) { string name = pi.Name; if (cols != "") { cols += ","; } cols += name; } sql = string.Format(sql, cols, tableName); return(AdoTemplate.DataTableUpdateWithCommandBuilder(ObjectHelper.CopyToDataTable <T>(listT.ToArray()), CommandType.Text, sql, null, tableName) > 0); } catch (Exception ex) { return(false); } }
/// <summary> /// 更新DataTable /// </summary> /// <param name="dt">要更新的DataTable</param> /// <returns></returns> public int UpdateDataTable(DataTable dt) { if (dt.Rows.Count == 0) { return(0); } int i = 0; try { string cols = "";//只处理影响到的字段。 DataTable dte = GetEmptyTable(dt.TableName); for (int j = 0; j < dt.Columns.Count; j++) { string col = dt.Columns[j].ColumnName; if (dte.Columns.Contains(col)) { if (cols != "") { cols += ","; } cols += "[" + col + "]"; } } string sql = "select " + cols + " from " + dt.TableName; i = AdoTemplate.DataTableUpdateWithCommandBuilder(dt, CommandType.Text, sql, null, dt.TableName); } catch (Exception e) { throw e; } return(i); }