本文介绍了浏览数据库记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3个用于从数据库中检索数据的文本框,以及4个拳头,上一个,下一个和最后一个按钮,可以帮助我浏览表的记录.
但是我对按钮预览和下一步的代码有疑问.
因为当我执行应用程序时,下一个按钮仅采用一个值(row=2),并且总是在我按下一个按钮时才将我引向表的第二条记录.
上一个按钮也会发生同样的事情,它仅占用表的第一条记录.
请告诉我我的代码有误吗?

I have 3 text boxes that retrieve data from the database and 4 buttons fist, previous, next and last that help me to navigate through the records of the table.
But I have a problem with the code of the button previews and next.
Because when I execute the application, the next button takes only one value (row=2) and always when I press the next button it leads me to the second record of the table.
the same thing happens with the previous button, it takes only the first record of the table.
Please tell me what I have made wrong to my code?

Imports System.Data.OleDb
Imports System.Data.SqlClient

Public Class default
    Inherits System.Web.UI.Page

    Dim Sql As String

    Dim inc As Integer = 0
    Dim ds As New DataSet
    Dim MaxRows As Integer
    Dim SQLConnection As Object

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        NavigateRecords()
    End Sub

    Private Sub NavigateRecords()

        Dim con As New OleDb.OleDbConnection
        Dim strCon As String = "Provider=SQLOLEDB; Data Source=192.168.131.72; Initial Catalog=Flex; User ID=sa; Password="

        con.ConnectionString = strCon

        con.Open()
        Dim ds As New DataSet
        Dim da As OleDb.OleDbDataAdapter

        Sql = "SELECT * FROM Customer"

        da = New OleDb.OleDbDataAdapter(Sql, con)
        da.Fill(ds, "Person")

        con.Close()
        MaxRows = ds.Tables("Person").Rows.Count
        txt_name.Value = ds.Tables("Person").Rows(inc).Item("2")
        txt_surname.Value = ds.Tables("Person").Rows(inc).Item("3")
        txt_city.Value = ds.Tables("Person").Rows(inc).Item("4")
    End Sub

    Protected Sub btn_next_Click(sender As Object, e As EventArgs) Handles btn_next.Click
        If (inc <> (MaxRows - 1)) Then

            inc = inc + 1

            NavigateRecords()

        End If
    End Sub

    Protected Sub btn_first_Click(sender As Object, e As EventArgs) Handles btn_first.Click
        If (inc <> 0) Then

            inc = 0

            NavigateRecords()

        End If
    End Sub

    Protected Sub btn_previews_Click(sender As Object, e As EventArgs) Handles btn_previews.Click

        If (inc > 0) Then

            inc = inc - 1

            NavigateRecords()
        End If
    End Sub

    Protected Sub btn_last_Click(sender As Object, e As EventArgs) Handles btn_last.Click
        If (inc <> (MaxRows - 1)) Then

            inc = MaxRows - 1

            NavigateRecords()

        End If
    End Sub

End Class

推荐答案


这篇关于浏览数据库记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 07:02