can't read integer field from database (ADO)

tommitommi Member Posts: 5
Hello,

i try to read a integer field from a database an write it into a field in navision, but i always get error messages.

I tried this:
NavTab.Reznr := ADOrs.Fields.Item('Reznr').Value;
but i got the message that this type is not supported in C/SIDE

The Evaluate function also doesn't work:
EVALUATE(MischprotokolleMH.Reznr, ADOrs.Fields.Item('Reznr').Value);

can somebody help me?

Answers

  • kinekine Member Posts: 12,562
    Check that there is no NULL value in the field. You cannot work with the NULL values in NAV and you need to test the field value size before you try to read the value.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • tommitommi Member Posts: 5
    The value in the field is never NULL there ist alwas an integer between 1 and 1000.
    What do you mean with testing the value size? That it is not bigger than "2147483647"?
  • kinekine Member Posts: 12,562
    No. There is property which tells you how big is the value saved in the field. If it is 0, it means that the value is NULL. If it is different, all is OK... it is used to detect NULL values.

    I am not sure, is it really possible to "address" the item through text? Did you try to address the item through integer? (indexing by integer and not text)...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • tommitommi Member Posts: 5
    Sorry i'm not so good in Navision programming. I don't realy know, what you mean.

    It works fine, when i want to read out a String field from the Database and write it into a String field in Navision:
    NavTab.Name := ADOrs.Fields.Item('Name').Value;
    
    but i can't find a way to read out an integer and write it into a navision integer field
  • EugeneEugene Member Posts: 309
    a field in a database table can have a value assigned to it or it can have no value assigned. The latter is usually reffered to as NULL value

    IF your integer type field was never assigned a number then it has no value assigned (has NULL value). NULL and 0 are not the same. Do not expect ADO to retun you value = 0 when the field in question has no value assigned (has NULL value)
  • ayhan06ayhan06 Member Posts: 210
    today i used this way (thanks Miklos Hollender)
        LOCAL PROCEDURE VariantToInteger@50002180(Variant@50002176 : Variant;VAR RetInt@50002175 : Integer) : Integer;
        BEGIN
          IF ISCLEAR(ADOStream) THEN
            CREATE(ADOStream);
          ADOStream.Open;
          ADOStream.WriteText(Variant);
          ADOStream.Position:= 0;
          EVALUATE(RetInt,ADOStream.ReadText);
          ADOStream.Close;
          EXIT(RetInt);
        END;
    

    possible usage is like that:
    IF VariantToInteger(ADORs.Fields.Item('Status').Value,OldStatusID2) = OldStatusID THEN
    
  • tommitommi Member Posts: 5
    Thanks Ayhan that works:

    New Function:
    VarianttoInteger(AVariant : Variant) RetInt : Decimal
          IF ISCLEAR(ADOStream) THEN
            CREATE(ADOStream);
          ADOStream.Open;
          ADOStream.WriteText(AVariant);
          ADOStream.Position:= 0;
          EVALUATE(RetInt,ADOStream.ReadText);
          ADOStream.Close;
          EXIT(RetInt);
    
    NavTab.Protokoll := VariantToInteger(ADOrs.Fields.Item('Protokoll').Value);
    
Sign In or Register to comment.