C# Outputting BCD Value from SQL returning only 0 as Decimal

MasterAtreu used Ask the Experts™
Currently I have built an application (using Visual Studio .Net MVC Web Application in C#) which opens up specific views in Sage 300, which I then use to pull specific table information. I am currently trying to get Quantity on Hand data (the number) from Sage 300's IC0290 ROTO ID View. The code I have will only bring back "0". It does bring back other information from the same table as long as the values for that information are strings. The value type for QTYONHAND is BCD*10.4 . I am trying to use Decimal in C# but it brings back a 0. I have the code listed below. If anyone has any ideas on how I can get the actual data to come through, I would greatly appreciate it.

private void OpenSessionDBandView()
        // Create, initialize and open a session.
        session = new Session();
        session.Init("", "XY", "XY1000", "62A");
        session.Open("ADMIN", "ADMIN", "SAMINC", DateTime.Today, 0);

        // Open a database link.
        mDBLinkOpen = session.OpenDBLink(DBLinkType.Company, DBLinkFlags.ReadWrite);

        // Open the I/C Items View - "IC0310"
        icItemView = mDBLinkOpen.OpenView("IC0310");

        // Open the I/C Items View (Quantities on Hand) - "IC0290"
        icLocationDetailsView = mDBLinkOpen.OpenView("IC0290");
    public string DoIt()
        string returnHTML;


        decimal itemQoH;
        // "itemNumber" is a value derived from a form created. User submits the item number.
        icLocationDetailsView.Fields.FieldByName("ITEMNO").SetValue(itemNumber, false);
        itemQoH = (decimal)icLocationDetailsView.Fields.FieldByName("QTYONHAND").Value;

        returnHTML = returnHTML + "Quantity on Hand = " + itemQoH;

        return returnHTML;}
The HTML then reads: "Quantity on Hand = 0.0000"

To test the connection and the table accuracy I used this code which worked correctly.

String itemAccountSetCode;

icLocationDetailsView.Fields.FieldByName("ITEMNO").SetValue(itemNumber, false);
itemAccountSetCode= (String)icLocationDetailsView.Fields.FieldByName("CNTLACCT").Value;

returnHTML = returnHTML + "Item Account Set Code  = " + itemAccountSetCode;
The HTML then reads: "Item Account Set Code = FIFO "

This is correct. Strings seem to work correctly but the numbers do not.

The API documentation lists the following:

Field = QTYONHAND Index = 7 Type = BCD*10.4 (This is where I believe the problem is)

This is the data for the value that worked:

Field = CNTLACCT Index = 63 Type = String*6

Hopefully this is enough information that someone might be able to assist me. I should also add I have attempted to convert the BCD into Decimal but I have had no success. Visual Studio also finds an exception if I try to label the variable as a string with the following error:

"unable to cast object of type 'system.decimal' to type 'system.string'."

Thank you again for you help in advance!
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Dustin SaundersCo-Founder and Chief Architect
Top Expert 2016

You'll likely need to convert the BCD value into it's corresponding decimal value.

Do you have a link to the API?

Do you have a same BCD value and the expected result?  If so, I can show you how to convert it.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial