I have the following code placed behind a button on a form:
VAR
DBFConnect Automation 'Microsoft ActiveX Data Objects 2.5 Library'.Connection";
DBFRecord Automation 'Microsoft ActiveX Data Objects 2.5 Library'.Recordset";
Customer Record 18;
CommDialog OCX 'Microsoft Common Dialog Control, version 6.0 (SP6)'";
Path Text[250];
CutOut Text[250];
Position Integer;
Length Integer;
FileToUse Text[30];
CLEAR(DBFConnect);
CLEAR(DBFRecord);
CLEAR(CommDialog);
CREATE(DBFConnect);
CREATE(DBFRecord);
CommDialog.DialogTitle := 'Open dBase files';
CommDialog.Filter := '(*.dbf)|*.dbf';
CommDialog.ShowOpen;
IF CommDialog.FileName = '' THEN
EXIT;
Position := 1;
CutOut := CommDialog.FileName;
Length := STRLEN(CommDialog.FileName);
WHILE Position <> 0 DO BEGIN
Position := STRPOS(CutOut,'\');
IF Position = 0 THEN
FileToUse := CutOut;
Path += COPYSTR(CutOut,1,Position);
CutOut := DELSTR(CutOut,1,Position);
END;
DBFConnect.Open('Provider=Microsoft.Jet.OLEDB.4.0;Data Source=' + Path + ';Extended Properties=DBASE III;');
DBFRecord.Open(FileToUse,DBFConnect); // Open file
IF NOT(DBFRecord.EOF) THEN
DBFRecord.MoveFirst();
IF NOT(DBFRecord.EOF) THEN BEGIN
REPEAT
Customer.INIT;
Customer."No." := FORMAT(DBFRecord.Fields().Item('CUSTOMER').Value); // No.
Customer.Name := DBFRecord.Fields().Item('Name').Value; // Name
Customer.Address := DBFRecord.Fields().Item('ADDR1').Value; // Address 1
Customer."Address 2" := DBFRecord.Fields().Item('ADDR2').Value; // Address 2
Customer.City := DBFRecord.Fields().Item('CITY').Value; // City
Customer.County := DBFRecord.Fields().Item('STATE').Value; // State
Customer."Post Code" := DBFRecord.Fields().Item('ZIP').Value; // Zip
Customer."Phone No." := DBFRecord.Fields().Item('PHONE').Value; // Phone
Customer.INSERT;
DBFRecord.MoveNext();
UNTIL DBFRecord.EOF;
END;
DBFRecord.Close();
DBFConnect.Close();
The Problem I'm having is if a filed in the dbf file has no value, and I'm trying to assign it to a field in Navision, I get an error message telling me that I'm using a wrong variant type. Does anyone know what to do with a blank value like this?
:?:
0
Comments
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
MESSAGE('Null Value: %1',FORMAT(DBFRecord.Fields().Item('ADDR2').Value));
EXIT;
but the error still occurs. I wish there was an IsError function. I don't think that c/AL will let me read from the ado control if it does not understand the data type.
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
IF DBFRecord.Fields().Item('ADDR1').ActualSize <> 0 THEN
Customer.Address := DBFRecord.Fields().Item('ADDR1').Value; // Address 1
Thanks for the help!
I traded my sanity for a railgun
Hi shrekut and all!
I've tried this above but the this error message is show up when I try to compile the source (F11):
I use 2.6 Navision, so the
Variant type of variable is not supported! :-k
Anyone can help me? :?:
Thank you!
A
VT_BOOL wich means, you can use a variant with a boolean value.
which means you can do:
navision_var := ado.field.value;
If ado.field.type is boolean.
So you got a list of datatypes. But there is for example no VT_TIME, making it impossible to use time variables (Or use strings, and parse them yourself.)
So if you use a datatype directly which is not on your list of VT's, you will get that error you mentioned.
Hope this makes sense
And for the null-vlues:
i use a function i found here on mibuso:
NULL(pfldCheck : Automation "'Microsoft ActiveX Data Objects 2.8
Library'.Field") : Boolean
But the method is OK.
Thanks again!
Could you post some code wich produces this error?
The InitVariablesValue and SetVariablesValue are sets the global variable because this is a Dataport Object! So first read every field to global variables, then I use these variables after this.
The ADO Connect procedure:
Variables:
Name DataType Subtype Length ADOConnection2 Automation 'Microsoft ActiveX Data Objects 2.8 Library'.Connection ADORecSet Automation 'Microsoft ActiveX Data Objects 2.8 Library'.Recordset ADOCommand Automation 'Microsoft ActiveX Data Objects 2.8 Library'.Command ADOStream Automation 'Microsoft ActiveX Data Objects 2.8 Library'.Stream pfldCheck Automation 'Microsoft ActiveX Data Objects Recordset 2.8 Library'.Field
In summary my problem is to check, if some field is NULL or EMPTY because I cannot handle these values in Navision 2.6.
Maybe I have to change my Access database, where the value is EMPTY there will be '0'? :?:
Did you get a solution of your problem. I am also having a same problem and dont know what to do!! ](*,)
Ashok
Help! I have use this example, but error in line:
DBFRecord.Open(FileToUse,DBFConnect); // Open file
Please help!