Convert nvarchar UD column to either string or integer throws error

Hi, I’m uplifting an existing bpm from 9.05 to 10.2.400. In the existing progress code we have a simple statement: OrderRel.OrderNum = INT(ttTFOrdDtl.ShortChar01). Note that ShortChar01 is of type nvarchar.

When I try this using C# I’m getting errors when I issue a similar statement: OrderRel.OrderNum = Convert.ToInt32(ttTFOrdDtl[“ShortChar01”]) 'Cannot convert from string to Int". If I try to use a variable to store the value of ttTFOrdDtl[“ShortChar01”] as a string I get the very same error.

I have tried variations of int.Parse(), Convert and even making everything a string, to no avail.

The code segment I’m working with:

string stringS01 = String.Empty;
int intS01 = 0;

var tfOrd = from ttTFOrdDtlRow in ttTFOrdDtl
where ttTFOrdDtlRow.RowMod == “A”
select ttTFOrdDtlRow[“ShortChar01”];

stringS01 = ttTFOrdDtl[“ShortChar01”]; // throws 'cannot convert from ‘string’ to ‘int’
intS01 = ttTFOrdDtl[“ShortChar01”]; // throws 'cannot convert from ‘string’ to ‘int’
intS01 = Convert.ToInt32(ttTFOrdDtl[“ShortChar01”]); // throws cannot convert from ‘string’ to ‘int’
stringS01 = Convert.ToString(ttTFOrdDtl[“ShortChar01”]); // throws cannot convert from ‘string’ to ‘int’

I must be doing/not doing something terribly basic because this does not seem like it should be at all complicated…??? Any help or pointing out of obvious gross errors is appreciated.

Thanks,Nick

so i’m not sure how you are getting any errors relating to string at all as your trying to use the object collection as your row variable which you defined as tfOrd. Also the row[“column”] notation is not ideal use object notation instead tfOrd.ShortChar01 or tfOrd.UDField(“ShortChar01”) . From there you will still need to do a ToString on your property and then int.parse or try parse if you like.

Looks like you are using the wrong variable @nmeszaros

 ttTFOrdDtl //is a table... at least in your code sample obove... as such you can't just get a field from it

Change it to something like this:

var stringS01 = (from ttTFOrdDtlRow in ttTFOrdDtl
where ttTFOrdDtlRow.RowMod == “A”
select ttTFOrdDtlRow[“ShortChar01”]).DefaultIfEmpty(“”).FirstOrDefault();

Thanks all for your guidance!