What's wrong with my code?

cunny
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?
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?
0
Answers
-
What is the error message you are getting?0
-
//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.0 -
Move your insert line outside the field loop.0
-
lubost wrote:Move your insert line outside the field loop.
! Thanks guys!
0 -
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?
thanksRegards,
GD0 -
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
cheers0
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