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

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;

        OpenSessionDBandView();

        decimal itemQoH;
        // "itemNumber" is a value derived from a form created. User submits the item number.
        icLocationDetailsView.Fields.FieldByName("ITEMNO").SetValue(itemNumber, false);
        icLocationDetailsView.Read(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);
icLocationDetailsView.Read(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!
MasterAtreuAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dustin SaundersDirector of OperationsCommented:
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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET MVC

From novice to tech pro — start learning today.