Solution from the comments:
Using fetchconn As New OleDbConnection(connStr)
Using cmdfetch As New OleDbCommand()
cmdfetch.Connection = fetchconn
cmdfetch.CommandText = "Select AssetBarcode from TrackingInfo Where AssetBarcode = ? AND CheckedOut = True"
cmdfetch.Parameters.AddWithValue("AssetBarcode", ChkOutBarcode.Text)
fetchconn.Open()
Using fetchreader As OleDbDataReader = cmdfetch.ExecuteReader(CommandBehavior.CloseConnection)
While fetchreader.Read()
If String.Equals(ChkOutBarcode.Text, fetchreader("AssetBarcode"), StringComparison.OrdinalIgnoreCase) Then
MessageBox.Show("Item has already been checked out. Please inform the Helpdesk")
Me.Close()
Return
End If
End While
End Using
End Using
End Using
As suggested in
your follow-up question[
^], the check in the code is redundant. You can simplify this to:
Using fetchconn As New OleDbConnection(connStr)
Using cmdfetch As New OleDbCommand()
cmdfetch.Connection = fetchconn
cmdfetch.CommandText = "Select CheckedOut from TrackingInfo Where AssetBarcode = ?"
cmdfetch.Parameters.AddWithValue("AssetBarcode", ChkOutBarcode.Text)
fetchconn.Open()
Dim result As Object = cmdfetch.ExecuteScalar()
If result Is Nothing Then
MessageBox.Show("This item does not exist. Please inform the Helpdesk")
Me.Close()
Else If CBool(result) Then
MessageBox.Show("This item has already been checked out. Please inform the Helpdesk")
Me.Close()
End If
End Using
End Using