Dim _tableBackLogs As System.Data.DataTable
Do While i - 2 > 0
_tableBackLogs = Global.DataAccess.GetDataTable("SELECT SubjectID,SubjectName,Grade FROM SubjectPI WHERE RegNo='" & CInt(HttpContext.Current.Session("userName")) & "' AND Status='Fail' AND Semester='" & i - 2 & "'")
i = i - 2
Loop
lvBackSubjects.DataSource = _tableBackLogs
lvBackSubjects.DataBind()
这样做只会绑定提供给i
的最后一个ListView
值的数据。我想要所有的数据。假设i=5
。所以我希望ListView
拥有i=3,1
的数据。希望我不要让你们困惑。
答案 0 :(得分:0)
看起来循环正在覆盖变量_tableBackLogs。做这样的事情可能会更好:
dim semesters as New System.Text.StringBuilder()
Do While i - 2 > 0
semesters.Append("'" & i & "',")
i = i - 2
Loop
' remove the last ,
semesters.Remove(semesters.Length -1,1)
_tableBackLogs = Global.DataAccess.GetDataTable("SELECT SubjectID,SubjectName,Grade FROM SubjectPI WHERE RegNo='" & CInt(HttpContext.Current.Session("userName")) & "' AND Status='Fail' AND Semester in (" & semesters.ToString() & ")"