Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Importing csv file to database
Message
From
09/11/2021 05:47:30
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01682654
Message ID:
01682661
Views:
43
>Assuming that the CSV you're importing from doesn't have multi-line fields and doesn't have fields longer than 255 characters, this simplest way might be to create a temporary cursor with the same structure as your database table but with the memo fields replaced with c(255)
>
>Then Copy the CSV into the cursor and then APPEND from the cursor to your database table.

BTW I'd recommend using v(255) instead of c(255), so the memos in the target table wouldn't contain trailing spaces.

Also assuming the memo fields don't contain any line breaks, but life is never so easy. For CSV exported from excel, libre and a few other sources, at least the line breaks inside multiline fields are LFs, while the record's EOL mark is a CR. Which then makes it feasible to do what Tamar recommends - copy into a variable using FileToStr(), break it into lines using aLines() (but specifying CR, not leaving it at default which recognizes both CR and LF), break it into fields at the tabs (comma is not recommended as separator, because you will have them inside memos too).

Beware also that your approach may work on a sample the customer provides - they are prone to sending something short and simple as a sample - and then break on a file coming from real life.

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Previous
Reply
Map
View

Click here to load this message in the networking platform