甜版主所说的方法,我也考虑过。不过,我没想着增加动态列,这个代码工作量有点大了。我是想着增加表达式列,但不给它赋公式,要用的时候给表达式赋值
本来是想借用“查询与赋值并存”中的思路
Dim Dic As new
Dictionary(of
DataRow, string)
For Each dr As DataRow In DataTables("子表").DataRows
dim r as datarow = DataTables("主表").find("ID = '" & dr("主表ID") & "'")
if r isnot nothing then
dic.Add(dr, r("列1"))
end if
Next
For Each
dr As
DataRow In
dic.Keys
dr("列X") = dic(dr)
Next
但貌似Dictionary不支持数组,例如 Dic As new Dictionary(of DataRow, string())
这样,如果有多列赋值就得定义多个dic,这个就有点小麻烦了
另外
Dim Dic As new
Dictionary(of
DataRow, Integer)
For Each dr As DataRow In DataTables("表A").DataRows
dic.Add(dr, dr("V"))
Next
For Each
dr As
DataRow In
dic.Keys
dr("第四列") = dic(dr)
Next
最后一段代码
for i as integer = 0 to dic.count - 1
dim dr as datarow = dic.keys(i) '--------这一段有错误吗?
next
就算是定义dim mm as datarow = dic.keys(0) '---这样也是会报错的。
报错为:
编译错误:类“System.Collections.Generic.Dictionary(Of DataRow, String()).KeyCollection”没有默认属性,因此无法被索引。 错误代码:Dim uu As DataRow = dic.Keys(0)
[此贴子已经被作者于2019/4/27 20:44:38编辑过]