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.
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.