简体   繁体   English

Visual Basic:如何在循环遍历 DataTable 行时删除特定列?

[英]Visual Basic: How to delete specific column while looping through DataTable rows?

I'm looping through the datatable as follows:我正在遍历数据表,如下所示:

For Each row As DataRow In records.Rows
    If row.Item("SYS_CHANGE_OPERATION") = "I" Then

    End If
Next

When the row meets the condition of the column, I need to remove an specific column of that same row.当行满足列的条件时,我需要删除同一行的特定列。

I know how to do it, if I want to remove a column from the whole DataTable.如果我想从整个 DataTable 中删除一列,我知道该怎么做。 Code is a simple as:代码很简单:

myDataTable.Columns.Remove("IdKey")

Simple code, yet, I don't find an answer around Google nor SO that explain how to remove a column withing the loop of rows.简单的代码,但是,我没有找到围绕 Google 的答案,也没有找到解释如何在行循环中删除列的答案。

Help!帮助! Thank you!谢谢!

Set cells empty:将单元格设置为空:

Dim x = dt.Rows.Cast(Of DataRow).Where(Function(r) r("SYS_CHANGE_OPERATION") = "I")
x.ToList().ForEach(Sub(r) r("SYS_CHANGE_OPERATION") = Nothing)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM