I work with vb6 and sql server, I need to know if a record exists for that I have a class to connect to the database.
Public cn As ADODB.Connection
Public rs As ADODB.Record
Public Sub Conectar()
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
rs.CursorLocation = adUseClient
' cn.Open "Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=gestvehicular;User=root;Password=123456;Option=3;"
cn.Open "Provider=SQLNCLI10;Server=.;Database=Northwind;Trusted_Connection=yes;"
End Sub
Public Sub Desconectar()
On Local Error Resume Next
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing
End Sub
I have created a Function in which I pass the id parameter of type integer to be able to make this query to the database
Public Function Existe(id As Integer) As Boolean
On Error GoTo tratarError
Dim cmd As New Command
Conectar
With cmd
.ActiveConnection = cn
.CommandText = "SELECT COUNT(*) FROM Employees WHERE EmployeeID=@id"
.CommandType = adCmdText
.NamedParameters = True
.Parameters.Append .CreateParameter("@id", adInteger, adParamInput, , id)
.Execute
If (rs.EOF) Then
End With
On Error GoTo 0
Desconectar
Exit Function
tratarError:
MsgBox Err.Description
End Function
With the query sql that I have if it exists in the database it gives me 1 and if it does not exist it gives me 0 then what I want to do is that if I give 1 that returns true
and if it gives 0 that returns false
I do not know how to do that with ADO.