简体   繁体   中英

Type of conditional expression cannot be determined because there is no implicit conversion between 'string' and 'int'

First off, I know this is a commonly asked question. But I cannot use other solutions because I am comparing types that cannot be delcared nullable types such as a DataRow type in my ternary operator. I also cannot format currency in my grid because I am pivoting my data and must have autogenerate columns set to true. I also cannot format currency somewhere else because I want one call to get the raw data and formatting to occur where is should. I need to use LinqSql because that is how I am preparing the data before binding it to a Telerik RadGrid

var drResults = from t1 in DatesTable.AsEnumerable()
                join t2 in dtResult.AsEnumerable() on t1["MONTH_YEAR"] equals t2["MONTH_YEAR"] into t1_t2
                from t2 in t1_t2.DefaultIfEmpty()
                select new
                {
                    MONTH_YEAR = t1.Field<string>("MONTH_YEAR"),
                    Appraisal_Fees = t2 != null ? String.Format("{0:C}", t2.Field<decimal>("AppraisalFees")) : 0): 0
                };

Try moving the ternary expression inside the argement to String.Format .

String.Format("{0:C}", (t2 != null ? t2.Field<decimal>("AppraisalFees") : 0M)) 

You could also make it easier to read by writing it on two lines:

decimal appraisalFees = (t2 != null ? t2.Field<decimal>("AppraisalFees") : 0M);
Appraisal_Fees = String.Format("{0:C}", appraisalFees);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM