What's wrong with my code?

cunnycunny Member Posts: 129
Objective:
Import the data to navision table from Access table through ADO!

Variables :
varRecordset @Automation 'Microsoft ActiveX Data Objects Recordset 2.8 Library'.Recordset
varFldCollection @Automation 'Microsoft ActiveX Data Objects Recordset 2.8 Library'.Fields
RecordVar @RecordRef
FieldVar @FieldRef

Code:
....
varRecordset.Open (strSql ,StrConnString); // Connection String

REPEAT
varFldCollection := varRecordset.Fields; // Extracting Fields Collection From Recordset and Storing in Fields Collection Object

RecordVar.OPEN(table_ID);
RecordVar.RESET;

FOR i :=1 TO RecordVar.FIELDCOUNT DO BEGIN
FieldVar :=RecordVar.FIELDINDEX (i);
FieldVar.VALIDATE(varFldCollection.Item(i-1).Value);
RecordVar.INSERT; //error occurs!
END;

varRecordset.MoveNext // moving to next record
UNTIL varRecordset.EOF=TRUE ;

Problem:
I can not insert the data which I retrieve from Access tabe into the RecordRef table. But when I use MESSAGE('Value of the field %1 is %2',FieldVar.CAPTION,FieldVar.VALUE); to show the value I can see they have been retrieved. What I want to do is insert the data into Navision table.

guys! any idear?
cunny Lee
MCP - MBS Navision
jle@naviworld.com

Answers

  • deltoiddeltoid Member Posts: 41
    What is the error message you are getting?
  • cunnycunny Member Posts: 129
    //Student ID '01' is already exists//.
    The Student is the table existing both in Access Database and Navision Native Database. And ID is the first primary key field of that table. '01' is the value I retrieve from access table for ID field and it's also the first retrieved value.
    cunny Lee
    MCP - MBS Navision
    jle@naviworld.com
  • lubostlubost Member Posts: 628
    Move your insert line outside the field loop.
  • cunnycunny Member Posts: 129
    lubost wrote:
    Move your insert line outside the field loop.
    Yes indeed! It works :lol: ! Thanks guys!
    cunny Lee
    MCP - MBS Navision
    jle@naviworld.com
  • gulamdastagirgulamdastagir Member Posts: 411
    hey,

    i tried using your code but its giving me an Error "the datatype is not supported by C/SIDE You can Access data From anyone of the following datatypes VT_VOID,VT_I2,VT_I4,.....VT_BOOL".

    strSql=SQL SERVER
    StrConnStringProvider=SQLOLEDB.1;
    Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=master;Data Source=GULAM

    Why is this happening and how can i fix this problem?

    thanks
    Regards,

    GD
  • ara3nara3n Member Posts: 9,256
    Hello the reason you are getting the error is because
    varFldCollection.Item(0).value is the timestamp.

    Make sure you exclude timestamp from your select statement or start from

    varFldCollection.Item(1).value

    cheers
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
Sign In or Register to comment.