Adaption of pdoxtrader's code
Public Function BusIdExists(ByVal busid As String) As Boolean
Dim thisSql As String = "SELECT Count(*) FROM [yourtable] WHERE busid=@busid"
Dim rowCount As Integer
' Get the list of rows with that busid
Using conn As New SqlConnection("your sql connect string")
conn.Open()
Using comm As New SqlCommand(thisSql, conn)
comm.Parameters.AddWithValue("@busid", busid)
rowCount = Convert.ToInt32(comm.ExecuteScalar())
End Using
End Using
Return (rowCount > 0)
End Function
1) I skipped the DataTable and DataReader objects - no need to instanciate those for this
2) I changed the sql and added Count(*) and removed the database name (that's selfevident from the connection string)
3) I added the busid using a parameter instead of concatenating a string. That's generally better praxis to avoid sql injections in more complex cases