Search Box Bizarre Behaviour

  • Thread starter Thread starter Aziz
  • Start date Start date
A

Aziz

I have created a search box that will compare the entered text with a
list of database entries and return the matches to a DataTable and
DataGrid

Private Sub txtProductCode_TextChanged(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles txtProductCode.TextChanged

Dim dtProductSearch As DataTable = New
DataTable("ProductSearch")
Dim dcProductSearch As DataColumn

dcProductSearch = New DataColumn
dcProductSearch.ColumnName = "ProductCode"
dtProductSearch.Columns.Add(dcProductSearch)
dcProductSearch.DataType = System.Type.GetType("System.String")
dcProductSearch = New DataColumn
dcProductSearch.ColumnName = "ProductDescription"
dcProductSearch.DataType = System.Type.GetType("System.String")
dtProductSearch.Columns.Add(dcProductSearch)
dcProductSearch = New DataColumn
dcProductSearch.ColumnName = "ProductAlloyCode"
dcProductSearch.DataType = System.Type.GetType("System.String")
dtProductSearch.Columns.Add(dcProductSearch)


Dim strSearched As String
strProductCode = txtProductCode.Text.ToUpper

Dim i As Integer
For i = 0 To dsTurbobraze.Product.Rows.Count - 1
strSearched =
dsTurbobraze.Product.Rows(i).Item("ProductCode").ToString

If InStr(strSearched, txtProductCode1.Text) > 0 Then
drProductSearch = dtProductSearch.NewRow()
drProductSearch("ProductCode") =
dsTurbobraze.Product.Rows(i).Item("ProductCode").ToString
drProductSearch("ProductDescription") =
dsTurbobraze.Product.Rows(i).Item("ProductDescription").ToString
drProductSearch("ProductAlloyCode") =
dsTurbobraze.Product.Rows(i).Item("AlloyCode").ToString
dtProductSearch.Rows.Add(drProductSearch)
dgrProductSearch.DataSource = dtProductSearch
End If
Next i
End Sub

I have 4 entries in the DataBase:
CHIAF-50-5-K2
CHIAF-50-5-K3
CHIAF-50-5-I4
CHIAF-50-5-M2

If I enter upto "CHIAF-50-5-" in the search box all results show up but
if I add a "K" nothing shows, if I add an "I" nothing shows, but if I
add an "M" it DOES show, and continues to show if I add a "2" to the
"M".

If I enter "K" on it's own, nothing shows, same with "I", but if I
enter "M" the correct product shows.

It seems to be a problem to do with the fact that either VB can't read
the last two letters of the ProductCode for all roducts except the last
one, or it can read it but can't process it for some reason.
 
If I output the contents of the DataSet the DataGrid is based on it
shows that when I type "K" the first two entries DO get added, they
just don't display in the DataGrid.

Debug.WriteLine(dtProductSearch.Rows.Count)
Dim i As Integer
For i = 0 To dtProductSearch.Rows.Count - 1
Debug.WriteLine(dtProductSearch.Rows(i).Item(0).ToString)
Next

When strSearched (string to look for) is "K" it gives:
2
CHIAF-50-5-K2
CHIAF-50-5-K3
 
Back
Top