You need to create a function that returns a boolean. This function would check the database to see if the string is present.
Something like this
Private Function CheckIfPresent(ByVal textToCheck As String)
Using con As SqlConnection = New SqlConnection("your connection string")
Dim cmd As SqlCommand = New SqlCommand("SELECT textField FROM yourTable WHERE textField = @textField", con)
cmd.Parameters.AddWithValue("@textField", textToCheck)
con.Open()
Dim dr As SqlDataReader = cmd.ExecuteReader()
Dim IsThere As Boolean = False
If dr.HasRows Then
IsThere = True
End If
dr.Close()
Return IsThere
End Using
End Function
and then in your TextBox's LostFocus event you just call this function
Private Sub TextBox1_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.LostFocus
Dim textToCheck As String = TextBox1.Text
If CheckIfPresent(textToCheck) Then
Else
End If
End Sub
Hope this helps