通过查询结果进行分页呢
民生视野 2021-08-24 13:34 字号: 大 中 小
public class Sample
{
static void Main()
{
n(new PagingSample());
}
}
[]
Imports System
Imports ta
Imports lClient
Imports awing
Imports rms
Public Class PagingSample
Inherits Form
\' Form controls.
Dim prevBtn As Button = New Button()
Dim nextBtn As Button = New Button()
Shared myGrid As DataGrid = New DataGrid()
Shared pageLbl As Label = New Label()
\' Paging variables.
Shared pageSize As Integer = 10 \' Size of viewed page.
Shared totalPages As Integer = 0 \' Total pages.
Shared currentPage As Integer = 0 \' Current page.
Shared firstVisibleCustomer As String = \"\" \' First customer on page to determine location for move previous.
Shared lastVisibleCustomer As String = \"\" \' Last customer on page to determine location for move next.
\' DataSet to bind to DataGrid.
Shared custTable As DataTable
\' Initialize connection to database and DataAdapter.
Shared nwindConn As SqlConnection = New SqlConnection(\"Data Source=.;Integrated Security=SSPI;Initial Catalog=northwind\")
Shared custDA As SqlDataAdapter = New SqlDataAdapter(\"\", nwindConn)
Shared selCmd As SqlCommand = lectCommand()
Public Shared Sub GetData(direction As String)
\' Create SQL statement to return a page of records.
ear()
Select Case direction
Case \"Next\"
mandText = \"SELECT TOP \" pageSize \" CustomerID, CompanyName FROM Customers \" _
\"WHERE CustomerID @CustomerId ORDER BY CustomerID\"
d(\"@CustomerId\", rChar, 5).Value = lastVisibleCustomer
Case \"Previous\"
mandText = \"SELECT TOP \" pageSize \" CustomerID, CompanyName FROM Customers \" _
\"WHERE CustomerID @CustomerId ORDER BY CustomerID DESC\"
d(\"@CustomerId\", rChar, 5).Value = firstVisibleCustomer
Case Else
mandText = \"SELECT TOP \" pageSize \" CustomerID, CompanyName FROM Customers ORDER BY CustomerID\"
\' Determine total pages.
Dim totCMD As SqlCommand = New SqlCommand(\"SELECT Count(*) FROM Customers\", nwindConn)
en()
Dim totalRecords As Integer = CInt(ecuteScalar())
ose()
totalPages = CInt(iling(CDbl(totalRecords) / pageSize))
End Select
\' Fill a temporary table with query results.
Dim tmpTable As DataTable = New DataTable(\"Customers\")
Dim recordsAffected As Integer = ll(tmpTable)
\' If table does not exist, create it.
If custTable Is Nothing Then custTable = one()
\' Refresh table if at least one record returned.
If recordsAffected 0 Then
Select Case direction
Case \"Next\"
currentPage += 1
Case \"Previous\"
currentPage += -1
Case Else
currentPage = 1
End Select
xt = \"Page \" currentPage \" of \" totalPages
\' Clear rows and add New results.
ear()
Dim myRow As DataRow
For Each myRow In ws
portRow(myRow)
Next
\' Preserve first and last primary key values.
改过自新。但是希望后来人不要期待这种奇迹发生 Dim ordRows() As DataRow = lect(\"\", \"CustomerID ASC\")
firstVisibleCustomer = ordRows(0)(0).ToString()
lastVisibleCustomer = ordRows(unt - 1)(0).ToString()
End If
End Sub
Public Sub New()
w
\' Initialize controls and add to form.
ientSize = New Size(360, 274)
xt = \"NorthWind Data\"
cation = New Point(10,10)
ze = New Size(340, 220)
lowSorting = true
ptionText = \"NorthWind Customers\"
adOnly = true
lowNavigation = false
eferredColumnWidth = 150
xt = \"\"
ze = New Size(48, 24)
cation = New Point(92, 240)
AddHandler ick, New EventHandler(AddressOf Prev_OnClick)
xt = \"\"
ze = New Size(48, 24)
cation = New Point(160, 240)
xt = \"No Records Returned.\"
ze = New Size(130, 16)
cation = New Point(218, 244)
d(myGrid)
d(prevBtn)
d(nextBtn)
d(pageLbl)
AddHandler ick, New EventHandler(AddressOf Next_OnClick)
\' Populate DataSet with first page of records and bind to grid.
GetData(\"Default\")
Dim custDV As DataView = New DataView(custTable, \"\", \"CustomerID\", rrentRows)
tDataBinding(custDV, \"\")
End Sub
Public Shared Sub Prev_OnClick(sender As Object, args As EventArgs)
GetData(\"Previous\")
End Sub
Public Shared Sub Next_OnClick(sender As Object, args As EventArgs)
GetData(\"Next\")
End Sub
End Class
Public Class Sample
Shared Sub Main()
n(New PagingSample())
End Sub
End Class
鏌ョ湅鏈枃鏉ユ簮
广州男科哪家好银川治疗男性功能障碍费用多少钱
天津宫颈糜烂治疗多少钱
-
-
巴神点拨老东家米兰该醒醒了最该买的人是他
巴神点拨老东家:米兰该醒醒了!最该买的人是他巴神:米兰...
2020-07-12 | 民生视野
-
-
贵州体育局开展2018至2019雪季冰雪
贵州体育局开展2018至2019雪季冰雪场所安全检查贵州省体育局...
2020-07-08 | 民生视野
-
-
包装变脸吓人一跳
包装“变脸” 吓人一跳 马硕 报道现在市面上的饮料是真不少...
2019-07-15 | 民生视野
-
-
钢城区大力宣传双拥政策
钢城区大力宣传双拥政策钢城区注重教育引导,努力做到“四...
2019-07-07 | 民生视野
-
-
市委组织部召开全市非公企业和社会组织党建
市委组织部召开全市非公企业和社会组织党建特派员动员暨培...
2019-07-07 | 民生视野
-
-
营养土不营养黄瓜苗难生长
营养土不营养 黄瓜苗难生长 记者 齐坤 报道 石家庄藁城...
2019-07-06 | 民生视野