This is what I have at the moment. It would not be the correct way to do this, but it does work. It will also throw a null error if a data item is returns is null. This error handeling type also depends on the textbox it is checking to be cleared each time you click the button.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
tbDateOfOrder.Clear()
tbProductID.Clear()
tbProductName.Clear()
tbQuantityOrdered.Clear()
tbQunatityInStock.Clear()
tbSupplierID.Clear()
tbItemCount.Clear()
Try
Dim b As String = My.Settings.dsstockConnectionString
Dim InputSearch As String = tbInput.Text
If InputSearch = " " Or InputSearch = Nothing Then
MsgBox("Nothing was input to search for", MsgBoxStyle.Critical, "No Input")
Else
Dim a As New OleDb.OleDbConnection(b)
a.Open()
Dim mySelect As String = ("SELECT[Product ID], [Product Name],[Qunatity in stock], [Quantity Ordered], [Date of order], [Supplier ID] FROM dsstock.STOCK")
Dim adapter As OleDbDataAdapter = New OleDbDataAdapter(mySelect, b)
Dim dscheckstock As DataSet = New DataSet
adapter.Fill(dscheckstock, "Stock")
For index = 0 To dscheckstock.Tables("Stock").Rows.Count - 1
Dim tblstock As DataTable
tblstock = dscheckstock.Tables("Stock")
If dscheckstock.Tables("stock").Rows(index).Item("Product ID").ToString.ToLower.Contains(InputSearch.ToLower) Or _
dscheckstock.Tables("stock").Rows(index).Item("Product Name").ToString.ToLower.Contains(InputSearch.ToLower) Then
tbProductID.Text = dscheckstock.Tables("Stock").Rows(index).Item("Product ID")
tbProductName.Text = dscheckstock.Tables("Stock").Rows(index).Item("Product Name")
tbQunatityInStock.Text = dscheckstock.Tables("Stock").Rows(index).Item("Qunatity in stock")
tbQuantityOrdered.Text = dscheckstock.Tables("Stock").Rows(index).Item("Quantity Ordered")
tbDateOfOrder.Text = dscheckstock.Tables("Stock").Rows(index).Item("Date Of Order")
tbSupplierID.Text = (dscheckstock.Tables("Stock").Rows(index).Item("Supplier ID"))
End If
Next
If tbProductID.Text = Nothing Then
MsgBox("Item Not found!" & "" & vbNewLine & InputSearch.ToString, MsgBoxStyle.Critical, "Item Not Found")
End If
a.Close()
tbItemCount.Text = dscheckstock.Tables("stock").Rows.Count
End If
Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try
End Sub