I have this function that should return 1 if the id exists and 0 if not.
When debugging I found that the query sent to sqlserver is correct and returns 1 row, also I see 1 in the ds Table count =1 but the function returns 0.
Is there a better way to do this ? And what is the problem?
Public Function check_id() As Integer
Try
connexion = New SqlConnection(chaine_de_connexion)
da = New SqlDataAdapter("select * from table_x where id=5", connexion)
ds = New DataSet
da.Fill(ds, "Info")
If ds.Tables("Info").Rows.Count > 0 Then
Return 1
Else
Return 0
End If
Catch ex As Exception
Return 0
End Try
End Function
The
check_id()function returns a YES or NO.. so why not use aBooleandata type?If you change the return type to
Booleanyou could do: