atlanticdit
IS-IT--Management
Hi All,
I have used code found here to find a record based on a keyword. I've developed from my limited knowledge a way to search for the next record with the same keyword. What I'm trying to do now is to figure out how to find previous records once I've passed them. I have a Previous button but this is to go back by one record and not by keyword. I've tried making the iCounter start with the record before the current one and end with the first record in the database but it didn't work. Kept telling me it couldn't find any records. This is a SQL 2000 database accessed through VB .NET 2003.
Any thoughts?
This is the code for finding a record based on a keyword: (thanks ThatRickGuy)
Dim iCounter As Integer
Dim bRecordFound As Boolean = False
Dim strKeyword As String
strKeyword = txtSearch.Text
For iCounter = 0 To DsTest1.Tables("Log").Rows.Count - 1
If DsTest1.Tables("Log").Rows(iCounter).Item("Date") = strKeyword Then
bRecordFound = True
Exit For
End If
Next
If bRecordFound Then
Me.BindingContext(DsTest1, "Log").Position = iCounter
Else
MessageBox.Show("Search string not found")
End If
The code for going to the Next record with the keyword is:
Dim iCounter As Integer
Dim bRecordFound As Boolean = False
Dim strKeyword As String
strKeyword = txtSearch.Text
For iCounter = Me.BindingContext(DsTest1, "Log").Position + 1 To DsTest1.Tables("Log").Rows.Count - 1
If DsTest1.Tables("Log").Rows(iCounter).Item("Date") = strKeyword Then
bRecordFound = True
Exit For
End If
Next
If bRecordFound Then
Me.BindingContext(DsTest1, "Log").Position = iCounter
Else
MessageBox.Show("Search string not found")
End If
Thanks,
Dave
I have used code found here to find a record based on a keyword. I've developed from my limited knowledge a way to search for the next record with the same keyword. What I'm trying to do now is to figure out how to find previous records once I've passed them. I have a Previous button but this is to go back by one record and not by keyword. I've tried making the iCounter start with the record before the current one and end with the first record in the database but it didn't work. Kept telling me it couldn't find any records. This is a SQL 2000 database accessed through VB .NET 2003.
Any thoughts?
This is the code for finding a record based on a keyword: (thanks ThatRickGuy)
Dim iCounter As Integer
Dim bRecordFound As Boolean = False
Dim strKeyword As String
strKeyword = txtSearch.Text
For iCounter = 0 To DsTest1.Tables("Log").Rows.Count - 1
If DsTest1.Tables("Log").Rows(iCounter).Item("Date") = strKeyword Then
bRecordFound = True
Exit For
End If
Next
If bRecordFound Then
Me.BindingContext(DsTest1, "Log").Position = iCounter
Else
MessageBox.Show("Search string not found")
End If
The code for going to the Next record with the keyword is:
Dim iCounter As Integer
Dim bRecordFound As Boolean = False
Dim strKeyword As String
strKeyword = txtSearch.Text
For iCounter = Me.BindingContext(DsTest1, "Log").Position + 1 To DsTest1.Tables("Log").Rows.Count - 1
If DsTest1.Tables("Log").Rows(iCounter).Item("Date") = strKeyword Then
bRecordFound = True
Exit For
End If
Next
If bRecordFound Then
Me.BindingContext(DsTest1, "Log").Position = iCounter
Else
MessageBox.Show("Search string not found")
End If
Thanks,
Dave