我有一个数据表,我试图检查数据表中的某一行是否为空或空。我有一个linq语句,我通过索引得到行,我能够看到行值,但我不知道如何检查值属于哪个列,以及值是null还是空。当我在foreach中时,如何找到列名和列值,在这种情况下,数据行称为“row”
int rowIndex = 9;
DataTable.AsEnumerable().Where((row, index) => index == rowIndex).ToList()
.ForEach(row => {
//Trying to iterate thru each column in the row
//Check the column Name that currently on
//get the value
});
答案 0 :(得分:0)
var ColumnToIngorn = DataTable.Columns["XXX"].Ordinal;
var ArrItem = DataTable.Rows[rowIndex].ItemArray.Where((item, indexColumn) => indexColumn != ColumnToIngorn);
foreach (var item in ArrItem)
...
或:
var ArrItem = DataTable.Rows[rowIndex].ItemArray.Select((item, indexColumn) => new { index = indexColumn, value = item });
foreach (var item in ArrItem)
{
if (item.index == 5) //Check index column
...
if (DataTable.Columns[item.index].ColumnName == "XXX") //check name column
...
}