31 lines
978 B
C#
31 lines
978 B
C#
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Web.Mvc;
|
|
|
|
namespace Kreta.Web.Helpers.Extension
|
|
{
|
|
public static class DataTableExtensions
|
|
{
|
|
public static void RemoveDataRowIfAnyColumnValueMatch(this DataTable dataTable, string columnName, List<int> columnValues)
|
|
{
|
|
if (!dataTable.Columns.Contains(columnName) || (dataTable.Columns[columnName].DataType != typeof(int?) && dataTable.Columns[columnName].DataType != typeof(int)))
|
|
{
|
|
return;
|
|
}
|
|
|
|
foreach (DataRow row in dataTable.Rows)
|
|
{
|
|
foreach (var columnValue in columnValues)
|
|
{
|
|
if (row.RowState != DataRowState.Deleted && row.Field<int?>(columnName) == columnValue)
|
|
{
|
|
row.Delete();
|
|
}
|
|
}
|
|
}
|
|
|
|
dataTable.AcceptChanges();
|
|
}
|
|
}
|
|
}
|