Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Import CSV file contents into database?

Status
Not open for further replies.

MC2NS

IS-IT--Management
Feb 21, 2002
1
US
Please excuse my simple question, this is my first aspect script. I am attempting to import data from a csv file into a database. I borrowed the script below and the "LineInfo" works if there is a single piece of data per line.

How do I get the second or third piece of comma delimeted data per line?

fgets 0 LineInfo ;get line from file
while not nullstr LineInfo
transmit LineInfo
transmit "^M"
pause 1
fgets 0 LineInf ;get line from file
endwhile
fclose 0
endif else
errormsg "File Doesn't Exist."
endif
endif
endproc
 
You can use the strtok command to break the contents of LineInfo into the delimited strings. Keep in mind that the strtok command will modify the original contents of LineInfo as it processes the string, so be sure to keep a backup of this variable if you need to reprocess the string again.

Here is an example I copied from the ASPECT help file that should get you going:

proc main
string DataStr ; String to contain data.
string ItemStr ; String to contain extracted item.

DataStr = "4D,61,72,6B,75,73" ; Assign hex values to data list.
while 1 ; Loop forever, or until EXITWHILE.
strtok ItemStr DataStr "," 1 ; Get first item from data list.
if nullstr ItemStr ; Check to see if item is null.
exitwhile ; If so, exit loop.
endif

usermsg "Data item is `"%s`"." ItemStr
endwhile
endproc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top