Results 1 to 10 of 10
  1. #1
    Join Date
    Mar 2004
    Posts
    8

    Unanswered: How to select everything from cursor into table

    Hi,
    I am trying to copy everything from cursor into table in the database:

    ......
    CLOSE DATABASES
    set path to "C:\Data\"
    SELECT * FROM mycursor;
    INTO TABLE "C:\Data\Table8";
    CLOSE TABLES ALL
    .....


    This is Foxpro program I call from VB. And for some reason getting an error
    "Automation error Exception occurs."

    I am not good at Visual Foxpro. So need help with this.

    Thanks.

  2. #2
    Join Date
    Aug 2004
    Posts
    28
    This should work for what you are trying to do.

    SELECT * ;
    FROM mycursor ;
    INTO TABLE C:\Data\Table8

    BTW... Ditch the Set Path command because you are hardcoding your path into the SQL statement unless of course you are using it for something else.


    AmcAmx

  3. #3
    Join Date
    Mar 2004
    Posts
    8
    Quote Originally Posted by amcamx
    This should work for what you are trying to do.

    SELECT * ;
    FROM mycursor ;
    INTO TABLE C:\Data\Table8

    BTW... Ditch the Set Path command because you are hardcoding your path into the SQL statement unless of course you are using it for something else.


    AmcAmx
    Thanks AmcAmx,

    it works if it is a free table. What to do if it belongs to the database?

  4. #4
    Join Date
    Aug 2004
    Posts
    28
    It should work the same. Try this before you run the query.

    OPEN DATABASE <database name> SHARED

    or try setting Exclusive to OFF.

    SET EXCLUSIVE OFF

    When you open a table in FoxPro it automatically opens the database that it is attached to (if it is NOT a free table) (it also will open the CDX associated witht he table). By setting EXCLUSIVE OFF it should allow you to open the database shared. The issue here is to make sure you RESET your EXCLUSIVE settings ( I am a firm believer that you should leave your environment in the state it was in when you arrived). So to do this you must store the current EXCLUSIVE setting.

    OldExclusive = SET("EXCLUSIVE")
    SET EXCLUSIVE OFF

    THen before you leave the function, procedure, method or program issue this:

    SET EXCLUSIVE &OldExclusive


    Hope this helps !

    AmcAmx

  5. #5
    Join Date
    Mar 2004
    Posts
    8
    I am about to throw my computer out of the window.
    No, it did not help. Now I am trying the workaround with this. And it looks like it does not know where to look for the table Attributes because I get asked to chose a table. When do I use SELECT <table> and when USE <table>?

    CLOSE DATABASES
    SET PATH TO "C\Data\"
    OPEN DATABASE Vendor
    *DISPLAY DATABASE

    SELECT reportcursor
    ? RECCOUNT( )
    * cursor is not empty.

    GO TOP
    DO WHILE .NOT. EOF()
    SELECT Attribite
    *USE Attribute
    LOCATE FOR f_vendor_number = fvendornumber
    IF FOUND()
    && If record exists then replace old status with updated status
    REPLACE f_vendor_status WITH vendorclassification
    ENDIF

    SKIP IN reportcursor
    SELECT reportcursor
    ENDDO

    Never mind. Problem resolved. It was simple syntax error.
    Last edited by Tala; 08-12-04 at 18:35. Reason: Problem resolved

  6. #6
    Join Date
    Aug 2004
    Posts
    28
    OK... Let me verify something. The last code you submitted is exactly like you typed it (in other words you are not levaing ANYTHING out) ? If this is the complete code then I also need to verify which tables you have open at the beginning of this code ? In order to do anything with a FoxPro table you have to USE it first (there are some exceptions to this).

    You do this by: USE MyTable IN 0 SHARED

    Then you have to select the WORKAREA of the table you wish to to anything to.

    It appears from the code above you are trying to SELECT the table when it is not open. This would give you the errors / issues you are stating.

    Hope this is helps...


    Btw... I will work with you to get this right... don't give up !

    Also, If you tell me what you are trying to accomplish maybe I can help too !

    AmcAmx
    Last edited by amcamx; 08-13-04 at 17:40.

  7. #7
    Join Date
    Mar 2004
    Posts
    8
    Thanks for helping me out.

    I have this cursor with updated vendor status. What I try to do is update the other table with this new status value. Whole program is pretty long and its main purpose - to create this cursor from different databases. Now I have to show this updated information using VB and Foxpro.
    I thought I had it working but I was wrong.


    I am attaching the program.

    Thanks.
    Attached Files Attached Files

  8. #8
    Join Date
    Aug 2004
    Posts
    28
    OK.. I presume that the code that is in issue is between :

    * MY POOR TRY:

    AND

    * END OF MY TRY


    A few more questions:

    When you run this ...

    1.) Does it display values for 1 -4 ?
    2. ) Does it EVER display "FOUND" ?


    Somehting I would consider changing....

    Change your "DO WHILE - ENDDO" loop to a "SCAN...ENDSCAN" loop.

    With Scan endscan you do not ned to keep track of your record pointer by using SKIP. THe scan will go to the next record when it hits the ENDSCAN
    AND... Yes you can have conditions in a SCAN...

    Another thing that you might wanna try is seting a relationship between the table and the cursor... then SCAN the Cursor for NOT EOF. this will go through all the records in your cursor that have records in the table. Then.. inside the SCAN loop you just do your replace statement.


    **************
    LIKE SO !
    **************

    * FIRST ! Create your index on your vendor table. (not in the program from the command window).
    INDEX ON f_vendor_number TAG VednorNum


    ************************************************** ************
    * This is AMCAMX's Try !

    * Open the vendor table, set its alias, and then set its order.
    USE tvendorattribute IN 0 shared ALIAS TheVendor ORDER VendorNum

    SELECT ReportCursor
    SET RELATION TO ReportCursor.fvendornumber INTO TheVendor ADDITIVE

    SCAN WHILE ! EOF("TheVendor")

    * Since the record DOES exist !
    REPLACE ;
    f_vendor_status WITH fclass, ;
    f_vendor_rating WITH frating
    ENDSCAN

    * END OF AMCAMX's TRY
    ************************************************** ************

    I think it will run this way... You may have to tweak some things around tho !

    I hope this helps !


    AmcAmx

  9. #9
    Join Date
    Mar 2004
    Posts
    8
    Dear AmcAmx,

    thank you very much! I finally got it to run and update the table.

    I am so grateful to you!

  10. #10
    Join Date
    Aug 2004
    Posts
    28
    No problem... Glad I could help !


    AmcAmx

Posting Permissions

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