通过查询结果进行分页呢
民生教育 2021-08-24 13:35 字号: 大 中 小
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
鏌ョ湅鏈枃鏉ユ簮
福州男科医院哪家医院好娄底男科医院
天津白癜风医院地址
-
-
马德里竞技VS埃瓦尔西蒙尼没有邀请莫拉塔搭配
马德里竞技 VS 埃瓦尔,西蒙尼:没有邀请莫拉塔马竞主帅西蒙...
2020-06-06 | 民生教育
-
-
山西完善临时救助制度紧急情况可先救助再审
山西完善临时救助制度 紧急情况可先救助再审批中新太原1月...
2019-12-17 | 民生教育
-
-
男子凌晨跑步偷走路虎称车主未锁车也应担责
男子凌晨跑步偷走路虎 称车主未锁车也应担责京华时报讯(记...
2019-07-16 | 民生教育
-
-
坪山新区全面发力加快东进
坪山新区全面发力加快东进深圳实施“东进”战略路途上,坪...
2019-07-13 | 民生教育
-
-
省会民心河换装打造城市新景观
省会民心河“换装” 打造城市新景观 (记者 徐艳 报道)...
2019-07-11 | 民生教育
-
-
安居区春风助老脱贫法律援助专项行动正式启
安居区“春风”助老脱贫法律援助专项行动正式启动安居区“...
2019-07-06 | 民生教育