Accessing data from Ms Access

aman_mbsaman_mbs Member Posts: 158
I have written the following code for insert data to navision tabel from access and encountering the following error.

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".

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
Constr Text 1024
StrSql Text 1024
i Integer

Code://

Constr := 'Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Access To Navision\Amantest.mdb;' +
'User Id=admin; Password=;';
StrSql := 'Select EmpCode, EmpName, EmpSalary, DOB From Employee';

CREATE(varRecordSet);
varRecordSet.Open(StrSql, Constr);
varRecordSet.MoveFirst;
RecordVar.OPEN(50001);
REPEAT
varFldCollection := varRecordSet.Fields;
RecordVar.RESET;
RecordVar.INIT;
FOR i := 1 TO RecordVar.FIELDCOUNT DO BEGIN
FieldVar := RecordVar.FIELDINDEX(i);
FieldVar.VALIDATE(varFldCollection.Item(i-1).Value);
END;
RecordVar.INSERT;
varRecordSet.MoveNext
UNTIL varRecordSet.EOF = TRUE;
varRecordSet.Close;
RecordVar.CLOSE;
CLEAR(varRecordSet);
CLEAR(RecordVar);

](*,)
Aman Kumar Gupta

Comments

  • garakgarak Member Posts: 3,263
    ](*,) please finish one post first before you create a new for this same topic!
    viewtopic.php?t=28720
    viewtopic.php?t=28702

    So, now to your problem.

    1. Where do you establish the ADOConnection?
    2. Where does this error pops up (wich line)? This info is very helpful ;-)
    3. ADO is very, very easy, search to forum, there are many posts.

    Here a simple example
    variables
    ADOConnection --> ‘Microsoft ActiveX Data Objects 2.8 Library’.Connection
    ADORecordSet  --> 'Microsoft ActiveX Data Objects 2.8 Library’.Recordset
    
    ConnectionString := 'PROVIDER=YOURPROVICER;SERVER=SQLServer;DATABASE=SQLDatabase;UID=SQLUserID;PWD=SQLPwd';
    ADOConnection.ConnectionString(ConnectionString);
    ADOConnection.Open; //now the connection is open
    
    SQLString := 'SELECT [Field 1],[Field 2] as ALIAS FROM [TABLE] WHERE [Some Field] < CONDITION';
    
    ADORecordSet := ADOConnection.Execute(SQLString,RecordsAffected,RSOption); //RecordsAffected returns the number of records fetched and RSOption sets how the provider should evaluate the commandtext parameter (SQLString). To know more about this, search (for example on msdn)
    
    //Now we parse trough the RecSet
    
    if ADORecordSet.MoveFirst then begin
      REPEAT
        YourTable.Field := ADORecordSet.Fields.Item(FIELDNAME).Value;
        YourTable.OtherField := ADORecordSet.Fields.Item(OtherFIELDNAME).Value;
        YourTable.insert;
        ADORecordSet.MoveNext;
      UNTIL ADORecordSet.EOF;
    end;
    
    //Now, when finished, we must close the RecSet and the connection.
    
    ADORecordSet.Close;
    ADOconnection.Close;
    
    Do you make it right, it works too!
  • aman_mbsaman_mbs Member Posts: 158
    Thanks for the reply but i found one thing as i remove the number field from the Access as navision my first code started working.. that means it has a problem in accessing the numeric value and i tried your code to it showing the same problem. please tell me how to access the numeric value too..

    Thanks
    Aman Kumar Gupta
Sign In or Register to comment.