【发布时间】:2018-04-18 17:30:35
【问题描述】:
我有以下代码,它根据custom_id 将行从DataTable 中删除为“Y”(即,如果键custom_id 的值在dictionary 中为“Y”,则删除该行) .现在我的列表fldListWithUnlimitedDataEnabled 中的记录很少,而DataTable objDt 中的记录相对较大,有没有办法从objDt 中删除特定的行(如objRow.Delete() 中所做的那样),这样我就不会必须遍历整个DataTable 以获得很少的记录?
Dim objRow As DataRow
Dim customFlds As Dictionary(Of String, String) = m_objCmnFncs.getCustomFlsdWithUnlimitedDataIndicator(strOrgId)
Dim fldListWithUnlimitedDataEnabled As List(Of String) = (From kv As KeyValuePair(Of String, String) In customFlds
Where kv.Value.Equals("Y")
Select kv.Key).ToList
If fldListWithUnlimitedDataEnabled.Count > 0 Then
For Each objRow In objDt.Rows
//The below condition effects the performance
If fldListWithUnlimitedDataEnabled.Contains(objRow("custom_id")) Then
objRow.Delete()
End If
Next
End If
【问题讨论】:
-
我知道这不是您要寻找的答案,但在您的示例中,您想要包含,而不是等于。
-
谢谢...编辑了问题
-
This 应该会给你一个想法。是c#,但是vb.net的概念是一样的。
标签: vb.net dictionary