Results 1 to 11 of 11

Thread: [RESOLVED] VB6 ADO error when adding WHERE clause in query

  1. #1

    Thread Starter
    Addicted Member *PsyKE1*'s Avatar
    Join Date
    Jun 2010
    Location
    Spain
    Posts
    243

    Resolved [RESOLVED] VB6 ADO error when adding WHERE clause in query

    I have a csv file with the following information:

    Code:
    NOMBRE,EDAD,FECHA
    MARIO,30,24/12/2002
    MARIA,90,24/12/2001
    PEDRO,10,24/12/2004
    Then I want to interact with it using ADO like this (I've added Microsoft ActiveX Data Objects 2.0 Library reference):

    Code:
    Dim oConn As New ADODB.Connection
    Dim oRS As New ADODB.Recordset
    
    oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" _
    & "Data Source=" & Environ("temp") & ";" _
    & "Extended Properties=""text;HDR=Yes;FMT=Delimited(,)"";Persist Security Info=False"
    
    Set oRS = oConn.Execute("select * from datos.csv")
    Dim ofield As ADODB.Field
    
    Do Until oRS.EOF
        For Each ofield In oRS.Fields
            Debug.Print "Field Name = " & ofield.Name & " Field Value = " & ofield.Value
        Next ofield
        oRS.MoveNext
    Loop
    It works! Returns:

    Code:
    Field Name = NOMBRE Field Value = MARIO
    Field Name = EDAD Field Value = 30
    Field Name = FECHA Field Value = 24/12/2002
    Field Name = NOMBRE Field Value = MARIA
    Field Name = EDAD Field Value = 90
    Field Name = FECHA Field Value = 24/12/2001
    Field Name = NOMBRE Field Value = PEDRO
    Field Name = EDAD Field Value = 10
    Field Name = FECHA Field Value = 24/12/2004
    But If I try to do a query like this:

    Code:
    SELECT EDAD FROM datos.csv WHERE NOMBRE='MARIO'
    I have the following error:

    Code:
    -2147467259 (800040005) Error in 'Execute' method of '_Connection' object.
    What am I dismissing? The only thing I've done is adding a 'where' clause in the query...
    If I compile the code, the same error appears:

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: VB6 ADO error when adding WHERE clause in query

    Does bracketing the table name resolve the problem?
    Code:
    SELECT EDAD FROM [datos.csv] WHERE NOMBRE='MARIO'
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    Addicted Member *PsyKE1*'s Avatar
    Join Date
    Jun 2010
    Location
    Spain
    Posts
    243

    Re: VB6 ADO error when adding WHERE clause in query

    Hi LaVolpe,

    Thank you, but I'm afraid it returns the same error.

  4. #4

    Thread Starter
    Addicted Member *PsyKE1*'s Avatar
    Join Date
    Jun 2010
    Location
    Spain
    Posts
    243

    Re: VB6 ADO error when adding WHERE clause in query

    Hi LaVolpe,

    Thank you, but I'm afraid it returns the same error.

  5. #5
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: VB6 ADO error when adding WHERE clause in query

    Just guessing here. I'm not on a VB machine & I've used similar code in dozens of projects to open/query csv files.

    One thing you are doing that I don't. I do not use .Execute to return recordsets only to execute update/delete queries. Suggest using oRS.Open vs oCnn.Execute. Also pick the type of recordset to return in the .Open command, i.e., OpenDynamic.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  6. #6

    Thread Starter
    Addicted Member *PsyKE1*'s Avatar
    Join Date
    Jun 2010
    Location
    Spain
    Posts
    243

    Re: VB6 ADO error when adding WHERE clause in query

    Thanks,

    following with your advice, this is my new code:
    Code:
    Dim oConn As New ADODB.Connection
    Dim oRS As New ADODB.Recordset
    
    oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" _
    & "Data Source=" & Environ("temp") & ";" _
    & "Extended Properties=""text;HDR=Yes;FMT=Delimited(,)"";Persist Security Info=False"
    
    oRS.Open "SELECT EDAD FROM [datos.csv] WHERE NOMBRE='MARIO'", oConn, adOpenDynamic, adLockReadOnly
    Dim ofield As ADODB.Field
    
    Do Until oRS.EOF
        For Each ofield In oRS.Fields
            MsgBox "Field Name = " & ofield.Name & " Field Value = " & ofield.Value
        Next ofield
        oRS.MoveNext
    Loop
    But returns:
    Code:
    -2147467259 (800040005) Error in 'Open' method of '_Recordset' object.

  7. #7
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: VB6 ADO error when adding WHERE clause in query

    Is your system locale set for Spanish? If so, bracket the field names too. On English systems, Name is a key word and without brackets, queries will fail. Similar with Date and other keywords used by SQL.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  8. #8

    Thread Starter
    Addicted Member *PsyKE1*'s Avatar
    Join Date
    Jun 2010
    Location
    Spain
    Posts
    243

    Re: VB6 ADO error when adding WHERE clause in query

    Yes, is set in spanish.
    But 'NOMBRE' or 'EDAD' are not keywords like 'NAME' or 'DATE'.

    Anyway I've changed it to:
    Code:
    oRS.Open "SELECT [EDAD] FROM [datos.csv] WHERE [NOMBRE]='MARIO'", oConn, adOpenDynamic, adLockReadOnly, adCmdText
    And now the error is:
    Code:
    2147217904 (8004e10)  There are no specified values for some of the required parameters.

  9. #9
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: VB6 ADO error when adding WHERE clause in query

    Quote Originally Posted by *PsyKE1* View Post
    Yes, is set in spanish.
    But 'NOMBRE' or 'EDAD' are not keywords like 'NAME' or 'DATE'.

    And now the error is:
    Code:
    2147217904 (8004e10)  There are no specified values for some of the required parameters.
    Well it was worth a shot, didn't know if locale's would be a factor or not.

    Since I really can't play along (i.e., test stuff myself), I'll back off and hopefully others may see the problem. In the mean time, have you looked at the FAQ portion of the forums regarding DBs?
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  10. #10
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: VB6 ADO error when adding WHERE clause in query

    I would suggest changing your reference from ADO 2.0 to ADO 2.5 as that is what most of us would be using. I haven't used 2.0 in many years can't remember what it does or does not support nor what bugs were in it. Try using 2.5 and see if you still get the error.

  11. #11

    Thread Starter
    Addicted Member *PsyKE1*'s Avatar
    Join Date
    Jun 2010
    Location
    Spain
    Posts
    243

    Re: VB6 ADO error when adding WHERE clause in query

    I've change the reference tu ADO 2.5 and now it works! THank you very much, DataMiser!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width