protected int UpdateRows(string table_name) { DataTable myTable = this.Tables[table_name]; DataRowCollection rows = myTable.Rows; int rowsCount = rows.Count; int rowsAffected = 0; if (rowsCount > 0) { var cmd = new UpdateStatement(myTable.ExtendedProperties["Storage"].ToString()); cmd.ConnectionStringName = _connectionStringName; var prmlist = new List <SqlParameter>(); int colsCount = myTable.Columns.Count; string identcol = String.Empty; for (int c = 0; c < colsCount; c++) { DataColumn col = myTable.Columns[c]; SqlParameter prm = new SqlParameter(col.ColumnName, col.DataType); prmlist.Add(prm); if (col.ExtendedProperties["PrimaryKey"] != null) { cmd.Where(Condition.IsEqual(col.ExtendedProperties["Storage"].ToString(), prm)); } else if (col.ExtendedProperties["NonStorable"] == null) { cmd.Column(col.ExtendedProperties["Storage"].ToString(), prm); } } IEnumerator rowEnum = rows.GetEnumerator(); while (rowEnum.MoveNext()) { DataRow row = (DataRow)rowEnum.Current; if (row.RowState == DataRowState.Modified) { for (int c = 0; c < colsCount; c++) { SqlParameter prm = prmlist[c]; prm.Value = row[prm.Name]; } cmd.Execute(); row.AcceptChanges(); rowsAffected++; } } } return(rowsAffected); }
public virtual void Remove(ICondition filter) { if (filter == null) { return; } var update = new UpdateStatement(_tableName) { ConnectionStringName = _connectionStringName }; var item = _metadata.Columns.First(x => x.Name == Entity.IS_REMOVED); if (item != null) { update.Column(item.ColumnName, SqlBoolean.TRUE); update.Where(filter); update.Execute(); } }