想要移动到数据集中的记录 - NON Query [英] Wanting to move to a record in a dataset - NON Query
问题描述
第一:用Visual Basic 2012编程(WinForm)。 SQLExpress 2012作为我的SQL服务器。
我在VB非常环保并尝试执行以下操作:
输入一个加载编号一个文本框。可以在2个字段(PETS_LOAD_NUMBER或PRIME_LOAD_NUMBER)中找到负载编号,但不能同时在两个字段中找到。一旦加载号被定位,我就想移动到数据集中的记录。我不想在只加载该记录的地方加载数据集。
本质上我想要复制MS ACCESS的功能,你可以在搜索框中键入它,它会自动转到记录中。
这是我到目前为止所遇到的一个问题。搜索框的初始使用要求我按两次输入。一旦找到结果并将其移动到记录中,那么任何后续搜索只需要轻按一次输入按钮,并且一切都按预期工作。
First: Programming with Visual Basic 2012 (WinForm). SQLExpress 2012 as my SQL server.
I am VERY green at VB and am attempting to do the following:
Input a Load Number into a Textbox. The load number will be found in one of 2 fields (PETS_LOAD_NUMBER or PRIME_LOAD_NUMBER) but not both. Once the load number is located I then want to move to the record in the dataset. I do not want a dataset loaded where only that record loads.
In essence I am wanting to replicate the functionality of MS ACCESS, where you type in the "search" box and it automatically goes to the record.
Here is what I have thus far but having one issue. The initial usage of the search box requires me to hit enter two times. Once the result is found and moved to the record, then any subsequent search requires only one tap of the enter button and all works as intended.
Private Sub NavSearchBtnLoad_Click(sender As System.Object, e As System.EventArgs) Handles NavSearchBtnLoad.Click
'General Declarations
Dim DB_REC_CNT As Int16 = LoadInfoDataSet.Load_Info_Table.Count 'Counts Records in Database
Dim SrchVal As String = SrchLoadInputAll.Text 'This is Load Number your searching for
Dim IdVal As Integer 'ID of record found
Dim SrchResult As Boolean = False 'Did search pass/fail default is fail
Dim LoopCnt As Int16 'Loop integer
'Perform Search
For LoopCnt = 0 To DB_REC_CNT - 1 ' Loops thru listboxes searching for the load number
Try
If LoadInfoDataSet.Load_Info_Table.Item(LoopCnt).PETS_LOAD_NUMBER = SrchVal Then SrchResult = True
If LoadInfoDataSet.Load_Info_Table.Item(LoopCnt).PRIME_LOAD_NUMBER = SrchVal Then SrchResult = True
If SrchResult = True Then
IdVal = LoopCnt
LoopCnt = DB_REC_CNT - 1 ' Stops searching before end of list if found
End If
Catch ex As Exception
End Try
Next
Try
If SrchResult = False Then
' Display a message box notifying users the record cannot be found.
If MessageBox.Show("NO RECORD FOUND. PLEASE RETRY YOUR SEARCH", "P.E.T.S. DATA MANAGEMENT SYSTEM", _
MessageBoxButtons.OK, MessageBoxIcon.Information) _
= DialogResult.OK Then
End If
Exit Sub
End If
Catch ex As Exception
End Try
'Copy ID to Navigator and Run
Try
Dim ID As String = LoadInfoDataSet.Load_Info_Table.Item(IdVal).ID
BindingNavigator1.PositionItem.Text = ID
'Code For clicking to go to selected record
BindingNavigatorPositionItem.Focus()
BindingNavigator1.Focus()
BindingNavigator1.Update()
Catch ex As Exception
End Try
End Sub
推荐答案
而不是使用
instead of using
BindingNavigator1.PositionItem.Text
尝试
Try
BindingNavigator1.BindingSource.Position
不得不在它的末尾添加一个-1因为结果把我的记录拉得太远了。 IE:BindingNavigator1.BindingSource.Position = ID - 1
除此之外,一切都很好 - 谢谢。
Had to add a "-1" to the end of it as the result took me one record too far. IE: BindingNavigator1.BindingSource.Position = ID - 1
Other than that, all is well - Thank you.
这篇关于想要移动到数据集中的记录 - NON Query的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!