我有一个100万行的SQLite数据库。显然,DGV在显示大量记录时失败了。所以我实现了分页,一次只显示50k条记录。
这很有效,但如果我想立即对DB中的所有数据进行处理/更新,我还没有找到解决方案,我一次只能做50k记录。我是否需要为每个块调用GetPage,进行处理,然后以编程方式移动到下一页,直到它们都没有剩下?我想DataReader会合适吗?
另外,使用分页,如果我从第1页中选择包含50k行的某些行,我也无法在DGV中选择第2页中的任何行,对吗?
Private connString As String = "Data Source=data.s3db;Version=3"
Private dt As DataTable
Private pageNumber As Integer
Private pageSize As Integer = 50000
Private adapter As SQLiteDataAdapter
Private Sub btnNext_Click(sender As Object, e As EventArgs) Handles btnNext.Click
pageNumber += 1
dt = GetPage(pageNumber * pageSize, pageSize)
DataGridView1.DataSource = dt
End Sub
Private Sub btnPrevious_Click(sender As Object, e As EventArgs) Handles btnPrevious.Click
pageNumber -= 1
dt = GetPage(pageNumber * pageSize, pageSize)
DataGridView1.DataSource = dt
End Sub
Public Function GetPage(startIndex As Integer, pageSize As Integer)
Dim table As New DataTable
Using adapter As New SQLiteDataAdapter("SELECT * FROM test LIMIT " & pageSize & " OFFSET " & startIndex, connString)
adapter.Fill(table)
End Using
Return table
End Function