Importing csv file

JackY
Member Posts: 3
I have a csv file I am importing data to update customer records using a codeunit.
I have successfully completed this task in the past but these records contain several boolean fields.
It seems that when I import the first record and attempt to assign the first field of data using SELECTSTR(1, TrainingInfoLine) it gives me the following message 'STRSET' cannot contain 'TRUE' more than once.
I wouldn't think this would normally cause a problem.
Any suggestions would be helpful. :?
I am running Financial 26e on a sql server 2000
I have successfully completed this task in the past but these records contain several boolean fields.
It seems that when I import the first record and attempt to assign the first field of data using SELECTSTR(1, TrainingInfoLine) it gives me the following message 'STRSET' cannot contain 'TRUE' more than once.
I wouldn't think this would normally cause a problem.
Any suggestions would be helpful. :?
I am running Financial 26e on a sql server 2000
0
Comments
-
The following code will show how to create your own selectstr function. This is neccessary beacuse selectstr cannot handle situations whre 2 substrings are equal.
GetFieldContent(parFieldNo : Integer;parTxt : Text[1024]) : Text[1024] ReturnString := ''; FieldsFound := 1; boo := -1; REPEAT CounterPOS += 1; IF parTxt[CounterPOS] = '"' THEN boo *= -1 ELSE BEGIN IF (parTxt[CounterPOS] = ',') AND (boo = -1) THEN FieldsFound += 1 ELSE IF FieldsFound = parFieldNo THEN ReturnString := ReturnString + COPYSTR(parTxt,CounterPOS,1); END; UNTIL (CounterPOS = STRLEN(parTxt)) OR (FieldsFound > parFieldNo); EXIT(ReturnString);
This works for me0 -
Thanks a lot. I only realised this limitation of SELECTSTR now, and your code saves me an hour or two of messing around.
AlastairAlastair Farrugia0 -
I'm just so glad to be of any assistance.
And by the way: Your post shows that it is a good idea to search the forum before posting new questions...0 -
i have trying to apply the code that was given by PrebenRasmussen.
am trying to instream a csv file that has 7 comma separated subtrings eg.
ABL,1480,1480,1480,2501,07/11/05,5456.79
this is how the code in the codeunit looks like:
OnRun()
Data.OPEN('C:\Rates.txt');
Data.CREATEINSTREAM(InS);
code := 1;
WHILE NOT (InS.EOS()) DO
BEGIN
InS.READTEXT(Txt);
Table.INIT;
Table."Equity Code" := GetFieldContent(1, Txt);
Table."Closing Price" := GetFieldContent(2, Txt);
Table."Opening Price" := GetFieldContent(3, Txt);
Table."Current Price" := GetFieldContent(4, Txt);
Table."Session No." := GetFieldContent(5, Txt);
Table."Date of Price Change" := GetFieldContent(6, Txt);
Table."GSE Index" := GetFieldContent(7, Txt);
Table.INSERT;
code := code + 1;
END;
Data.CLOSE();
MESSAGE('Records have been written');
and the
GetFieldContent(parFieldNo : Integer;parTxt : Text[1024]) : Text[1024]
ReturnString := '';
FieldsFound := 1;
int := -1;
REPEAT
CounterPOS += 1;
IF parTxt[CounterPOS] = '"' THEN
int *= -1
ELSE BEGIN
IF (parTxt[CounterPOS] = ',') AND (int = -1) THEN
FieldsFound += 1
ELSE
IF FieldsFound = parFieldNo THEN
ReturnString := ReturnString + COPYSTR(parTxt,CounterPOS,1);
END;
UNTIL (CounterPOS = STRLEN(parTxt)) OR (FieldsFound > parFieldNo);
EXIT(ReturnString);
please help out i need cos i need it badly.thank u ](*,)0 -
Hi magnifique
You could try this
Table."Equity Code" := COPYSTR(Txt,1,strpos(Txt,',') - 1);
Txt := COPYSTR(Txt,strpos(Txt,',') + 1);
Table."Closing Price" := COPYSTR(Txt,1,strpos(Txt,',') - 1);
Txt := COPYSTR(Txt,strpos(Txt,',') + 1);
etc for all the fields that are used.
Hope this helps
Albert0 -
thanx am about to try it and would give you a feedback the very moment am done.0
-
I use this code
lastpos := STRPOS(text,','); temp := COPYSTR(text,1,lastpos-1); EVALUATE(Testart.eins,temp); text := DELSTR(text,1,lastpos);
you can use this for every element in the CSV-file0 -
guys Albertvh code worked for me thanks so much .Frankie i will try yours later to see how it goes.Thanks everyone u saved the day.i guess navision with tyme will become as easy as ABC . this an appluase for all the help =D>0 -
-
You are MOST welcome...0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions