Here's what I've done. Keep in mind that, in my search I was looking to see if an existing account number exists. But you can do the same thing with names, addresses, etc. Just change the data field you're searching.
Dim con As New SqlConnection
Dim cmd As New SqlCommand
Dim query As String = "Select Count (*) As CustAccntNo FROM CustRec WHERE CustAccntNo = @AcctNo"
Try
con.ConnectionString = "Data Source=(LocalDB)\MSSQLLocalDB;Initial Catalog=C:\USERS\DON\DOCUMENTS\SALES.MDF;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"
con.Open()
cmd.Connection = con
cmd = New SqlCommand((query), con)
cmd.Parameters.AddWithValue("@AcctNo", SqlDbType.BigInt).Value = Convert.ToInt64(tbxAccntNo.Text)
execScarlar = Convert.ToInt64(cmd.ExecuteScalar())
Catch ex As Exception
MessageBox.Show("Invalid" & ex.Message)
Finally
con.Close()
End Try
If execScarlar <> 0 Then
MessageBox.Show("Account No. " & tbxAccntNo.Text & " has already been used. Please use another account number.", "Customer Account Number")
tbxAccntNo.Text = ""
tbxAccntNo.Select()
Exit Sub
End If