首页 >> 民生教育

通过查询结果进行分页呢

民生教育  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

鏌ョ湅鏈枃鏉ユ簮

福州男科医院哪家医院好
娄底男科医院
天津白癜风医院地址
推荐资讯