Vb.net 根据文本框中的特定值移动到下一条记录

Vb.net 根据文本框中的特定值移动到下一条记录,vb.net,Vb.net,我需要一些帮助。我希望能够使用动态数据库使用表单上的“下一步”和“上一步”按钮浏览记录 价值观 我当前拥有的代码确实会移动到下一条记录,但从起始值开始,但是我希望能够从特定值开始,例如,如果我键入100 进入文本框并单击next,每次单击都会显示101、102等的记录 我如何做到这一点。非常感谢 这是我目前的代码 Dim intcurrentindex As Integer = 0 If intcurrentindex < ds.Tables(0).Rows.Count - 1 Then

我需要一些帮助。我希望能够使用动态数据库使用表单上的“下一步”和“上一步”按钮浏览记录 价值观

我当前拥有的代码确实会移动到下一条记录,但从起始值开始,但是我希望能够从特定值开始,例如,如果我键入100 进入文本框并单击next,每次单击都会显示101、102等的记录

我如何做到这一点。非常感谢

这是我目前的代码

Dim intcurrentindex As Integer = 0
If intcurrentindex < ds.Tables(0).Rows.Count - 1 Then
    intcurrentindex = intcurrentindex - 1

    TextBox1.Text = ds.Tables(0).Rows(intcurrentindex).Item("NAME").ToString
    TextBox2.Text = ds.Tables(0).Rows(intcurrentindex).Item("CODE").ToString
    TextBox3.Text = ds2.Tables(0).Rows(intcurrentindex).Item("STOCKNAME").ToString
    TextBox4.Text = ds.Tables(0).Rows(intcurrentindex).Item("WEIGHT").ToString
    TextBox5.Text = ds.Tables(0).Rows(intcurrentindex).Item("LOCATION").ToString

End If
Dim intcurrentindex作为整数=0
如果intcurrentindex
可能是这样的:

Public Class Form1

Private intcurrentindex As Integer = 0
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    TxtCurrentIndex.Text = 0
End Sub

Private Sub BtnNext_Click(sender As Object, e As EventArgs) Handles BtnNext.Click

    If TxtCurrentIndex.Text = "" Then
        intcurrentindex = 0
    Else
        'set intcurrentindex to textbox value
        intcurrentindex = TxtCurrentIndex.text
    End If

    If intcurrentindex < ds.Tables(0).Rows.Count - 1 Then
        TextBox1.Text = ds.Tables(0).Rows(intcurrentindex).Item("NAME").ToString
        TextBox2.Text = ds.Tables(0).Rows(intcurrentindex).Item("CODE").ToString
        TextBox3.Text = ds2.Tables(0).Rows(intcurrentindex).Item("STOCKNAME").ToString
        TextBox4.Text = ds.Tables(0).Rows(intcurrentindex).Item("WEIGHT").ToString
        TextBox5.Text = ds.Tables(0).Rows(intcurrentindex).Item("LOCATION").ToString
        intcurrentindex = intcurrentindex + 1
    End If
End Sub

Private Sub BtnPrevius_Click(sender As Object, e As EventArgs) Handles BtnPrevius.Click

    If TxtCurrentIndex.Text = "" Then
        intcurrentindex = 0
    Else
        'set intcurrentindex to textbox value
        intcurrentindex = TxtCurrentIndex.text
    End If


    If intcurrentindex > 0 Then
        TextBox1.Text = ds.Tables(0).Rows(intcurrentindex).Item("NAME").ToString
        TextBox2.Text = ds.Tables(0).Rows(intcurrentindex).Item("CODE").ToString
        TextBox3.Text = ds2.Tables(0).Rows(intcurrentindex).Item("STOCKNAME").ToString
        TextBox4.Text = ds.Tables(0).Rows(intcurrentindex).Item("WEIGHT").ToString
        TextBox5.Text = ds.Tables(0).Rows(intcurrentindex).Item("LOCATION").ToString
        intcurrentindex = intcurrentindex - 1
    End If
End Sub
公共类表单1
私有intcurrentindex为整数=0
私有子表单1_Load(发送方作为对象,e作为事件参数)处理MyBase.Load
TxtCurrentIndex.Text=0
端接头
私有子BtnNext\u单击(发送者作为对象,e作为事件参数)处理BtnNext。单击
如果TxtCurrentIndex.Text=”“,则
intcurrentindex=0
其他的
'将intcurrentindex设置为文本框值
intcurrentindex=TxtCurrentIndex.text
如果结束
如果intcurrentindex0,则
TextBox1.Text=ds.Tables(0).行(intcurrentindex).项(“名称”).ToString
TextBox2.Text=ds.Tables(0).行(intcurrentindex).项(“代码”).ToString
TextBox3.Text=ds2.Tables(0).Rows(intcurrentindex).Item(“STOCKNAME”).ToString
TextBox4.Text=ds.Tables(0).行(intcurrentindex).项(“权重”).ToString
TextBox5.Text=ds.Tables(0).行(intcurrentindex).项(“位置”).ToString
intcurrentindex=intcurrentindex-1
如果结束
端接头
末级


您需要一个变量来存储当前索引

谢谢大家的帮助。我最终使用了绑定源代码使其工作。

文本框中的输入从哪里获取?您是否尝试添加
文本框
并使用
Int32.TryParse
获取其值?intcurrentindex为零,然后从中减去1,使intcurrentindex等于-1。不知道这是怎么回事。@David-我不知道该怎么处理。你能解释一下吗。我从textbox2@user3562155:那么,你具体被困在哪里?您声称从“textbox2”获取输入,但您在哪里这样做?您只是在问如何读取
文本框的值吗?这将在其
.Text
属性中。(方便地在您向
文本框
写入值的同一个位置)不清楚您具体被卡在哪里。@David-我可以输入一个值,比如112,然后检索记录,但当我单击“下一步”按钮时,我想让它做的是显示下一个连续的记录113、114等,而当前没有这样做。相反,当我单击“下一步”按钮时,它将从第一条记录开始,比如说100.fixed code,TxtCurrentIndex,它是文本框的名称,在这里输入记录编号这种代码很有效,但编号不是按顺序排列的,例如100101102103,它会在某些记录上崩溃。它给出了“从字符串“00450ABC1”到类型“整数”的转换无效”错误。