0
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

这样做会替换DataTable. 我想保留以前的数据,即我希望将新行添加到 DataTable 中而不替换以前的行。

4

2 回答 2

1

用以下代码替换您的代码。

Dim _tableBackLogs As New System.Data.DataTable

Do While i - 2 > 0
    _tableBackLogs.Merge(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
于 2012-04-15T03:38:13.073 回答
0

使用合并方法

Dim  _tableBackLogs As System.Data.DataTable

Do While i - 2 > 0
_tableBackLogs.Merge(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
于 2012-04-14T09:19:28.933 回答