ADO recordset getting no records from ADO command

I have the following code which comes from a class module I use for managing an Access 2000 database (from vb6 sp5)

Public Function SeleccionId(cnnDIMENSION As ADODB.Connection, ByRef rsResultado As ADODB.recordset, di_clave As Variant) As Boolean
On Error GoTo Error_SeleccionId
   
Dim lcdi_clave As ADODB.Parameter
   
    Set cmdDIMENSION = New ADODB.Command
    Set lcdi_clave = New ADODB.Parameter
   
    lcdi_clave.Type = adInteger
    lcdi_clave.Direction = adParamInput
    lcdi_clave.Size = 4
    lcdi_clave.Value = di_clave
    cmdDIMENSION.Parameters.Append lcdi_clave
   
    cmdDIMENSION.ActiveConnection = cnnDIMENSION
    cmdDIMENSION.CommandText = "DIMENSION_Select_Id_Qry"
    cmdDIMENSION.CommandTimeout = 30
    Set rsResultado = cmdDIMENSION.Execute()
   
    SeleccionId = True
    Set cmdDIMENSION = Nothing
    Exit Function
   
Error_SeleccionId:
    SeleccionId = False
    Set cmdDIMENSION = Nothing
   
End Function

I have tested the ADODB.connection that the function recieves as parameter and it's working fine, the recordset it recieves is an empty one (just declared and instantiated before being sent)... the idea is that this command activates an Access Query named "DIMENSION_Select_Id_Qry", which redaction I put here:

SELECT [di_clave], [di_nombre], [di_descripcion]
FROM DIMENSION
WHERE (di_clave like di_clave_qry);

This query, ran from Access works fine, and as you see, it has only one parameter "di_clave_qry". The problem here is that after the line Set rsResultado = cmdDIMENSION.Execute(), the rsResultado recordset gets no records at all (recordcount = -1), and I don't know what might be wrong. Could you please help me find the error?? I'm using ADO 2.7. Thanks beforehand.
pireAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

appariCommented:
dont check recordcount property because its not the same all the times and it depends on the cursor type. to check whether recordset is empty or not check for EOF like this

Public Function SeleccionId(cnnDIMENSION As ADODB.Connection, ByRef rsResultado As ADODB.recordset, di_clave As Variant) As Boolean
On Error GoTo Error_SeleccionId
   
Dim lcdi_clave As ADODB.Parameter
   
    Set cmdDIMENSION = New ADODB.Command
    Set lcdi_clave = New ADODB.Parameter
   
    lcdi_clave.Type = adInteger
    lcdi_clave.Direction = adParamInput
    lcdi_clave.Size = 4
    lcdi_clave.Value = di_clave
    cmdDIMENSION.Parameters.Append lcdi_clave
   
    cmdDIMENSION.ActiveConnection = cnnDIMENSION
    cmdDIMENSION.CommandText = "DIMENSION_Select_Id_Qry"
    cmdDIMENSION.CommandTimeout = 30
    Set rsResultado = cmdDIMENSION.Execute()
   
 if  rsResultado.EOF then
    Msgbox "No Data "
    SeleccionId = False
  else
    SeleccionId = True
  end if
    Set cmdDIMENSION = Nothing
    Exit Function
   
Error_SeleccionId:
    SeleccionId = False
    Set cmdDIMENSION = Nothing
   
End Function
0
appariCommented:
ignore " ", my windows OS is Japanese so by mistake typed something in japanese,

" if  rsResultado.EOF then " should be "if  rsResultado.EOF then"
0
JNSTAUBCommented:
SELECT [di_clave], [di_nombre], [di_descripcion]
FROM DIMENSION
WHERE (di_clave like di_clave_qry);
 where is your parameter lcdi_clave  in this query, the right query may be:
WHERE (di_clave like lcdi_clave);

i am not sure of the answer
 
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

kamlesh_agrawalCommented:
The recordcount works only when if you use cursor location as aduseclient...


replace this statement
    Set rsResultado = cmdDIMENSION.Execute()
   
with

     rsResultado.Cursorlocation = adUseClient
        Set rsResultado = cmdDIMENSION.Execute()


Hope it would help u ... make sure u've included adovbs.inc file at the top.. you can search "adovbs.inc" file in google and download it..


Kamlesh A.
0
kamlesh_agrawalCommented:
Oops it is in VB .. then it is ok if you dont include the file...
I thought it is ASP

bye
Kamlesh A.
0
atp_expertCommented:
I feel that, the recordset has data.. Just check if the recordset if EOF =BOF, if that is case then the recordset is empty.  

Change the cursor location to client side cursor. The default cursor type is forward only.
0
fsaimsCommented:
SELECT [di_clave], [di_nombre], [di_descripcion]
FROM DIMENSION
WHERE (di_clave like di_clave_qry);

Dear Pire in your above query di_clave_qry is taken as value, not as parameter. Change your Query with this

SELECT [di_clave], [di_nombre], [di_descripcion]
FROM DIMENSION
WHERE (di_clave like ?);
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Valliappan ANSenior Tech ConsultantCommented:
I think fsaims is right. Also if you use wild chars, then you need to consider:

http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/Articles/Q162/9/77.asp&NoWebContent=1
(ACC97: ASP Query Cannot Be Used with the LIKE Predicate)
- Hope, this uses ADO so apply to VB too.

http://support.microsoft.com/default.aspx?scid=http://support.microsoft.com:80/support/kb/articles/q163/8/93.asp&NoWebContent=1

http://support.microsoft.com/default.aspx?kbid=813696
(FIX: Parameter Query on Linked Tables Returns No Records)

Hope it helps.
0
Anthony PerkinsCommented:
Please maintain your open questions:

1 11/23/2002 100 Problem installing and running CR8 with ...  Open Crystal Reports
2 01/15/2003 100 Creating ContinuosTickets  Open Crystal Reports
3 07/08/2003 250 Error when accessing DataWindow in desig...  Open PowerBuilder
4 09/23/2003 500 USB mass storage device was formatted an...  Open Hardware
5 09/26/2003 150 Ideal drive distribution on IDE setup  Open Hardware
6 09/29/2003 100 Some software unexpectedly closes while ...  Open Windows XP
7 10/13/2003 100 Finding a full open source project.  Open .NET

Thanks,
Anthony
0
pireAuthor Commented:
Well... I've given maintenance to my EE account, and I'm reviewing the answers that the experts so kindly have given to this question, I'll post results ASAP. Thanks.
0
DanRollinsCommented:
Moderator, my recommended disposition is:

    Accept fsaims's comment(s) as an answer.

Dan Rollins -- EE database cleanup volunteer
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.