蓝老师好!遇到下面的问题,刷新数据后弹出的的数量有时是对的,有时是“0”,不知道是什么原因?
逻辑如下:
单词表的逻辑列[通过]列,是根据不同的练习人,查询在“练习日志”表格中的[通过单词]列,记录的单词来赋值的。请看代码及注释:
'获取通过信息
Dim Sum As Double ’预设更新数量
Dim dr As DataRow
dr = DataTables("设置表").sqlFind("用户 = '" & _UserName & "'")
If dr IsNot Nothing Then '如果找到的话
DataTables(dr("默认阶段")).ReplaceFor("通过", False) '先清除通过勾选
Dim str As String ="" '获取该用户通过的单词
Dim dr0s As List(Of DataRow)
dr0s = DataTables("练习日志").SQLSelect("[练习人] = '" & _UserName & "' And [练习年份]= '" & Date.Today.Year & "年'") '本年通过的单词
For Each dr0 As DataRow In dr0s
str += dr0("通过单词") & "、"
Next
Dim Values() As String '集合去重到新集合
Values = str.replace("、、","、").Trim("、").split("、")
Dim lts As New List(Of String)
Dim lt As String
For Index As Integer = 0 To Values.Length - 1
If lts.Contains(Values(Index)) = False Then
lts.add(Values(Index))
End If
Next
For Each lt In lts '新集合的值遍历,为逻辑列赋值
DataTables(dr("默认阶段")).SQLReplaceFor("通过", 1, "单词 = '" & lt.Replace("'","''") & "'")
Next
End If
Sum = DataTables(dr("默认阶段")).Compute("Count(通过)", "通过 = 1")
DataTables(dr("默认阶段")).LoadFilter = ""
DataTables(dr("默认阶段")).Load
msgbox("刷新完毕!" & vbcrlf & "共通过" & Sum & "个单词。")
此主题相关图片如下:截屏图片 (1).jpg