What code have you tried? You seem to already have the basic concept down. What you need to do is query the database, then check if any rows returned. It's that simple. Your SQL would look something like this:
SELECT year FROM table WHERE year=2013
You could use this to fill a table and then check if the table has any rows (
dtTable.Count = 0
). Or you could use this with an execute scalar and see if it equals
DBNull.Value
or
Nothing
which would mean it wasn't found in the database.
Or you could use the SQL function COUNT() like this:
SELECT COUNT(*) FROM table WHERE year=2013
and execute scalar. Then you'd just have to check if it was zero.
********* UPDATE *********
Now that you've posted your SQL code, the above will only work if you change your sql line to something like this:
sql = "SELECT * FROM App WHERE yearColumn=" & x
Where the "yearColumn" is whatever name your App table has for the column that contains the year.
If you want to continue to use your old sql line, that's fine...you'll just want to search it for the year in question, which you appear to be storing in the variable named
x
. (I'd recommend changing that variable name to something more meanningful, such as intYear if it's an integer value). To do that, you can simply do a .Select() on the table after you have filled it....it would look something like this:
If tblapp.Select("yearColumn=" & x).Count > 0 Then
End If