简体   繁体   中英

Why Crystal Reports not showing int, DateTime, double, money fields etc?

I have set the objct of a class as the datasource of the CR. All the string fields appear in the Fields Explorer in the design alright. But what happen to the numeric or datetime fields? How do I bring them?

public class ClsOutDocket
{
    public string RegistrationNo { get; set; }        
    public double? WeightIn { get; set; }        
    public DateTime? DateIn { get; set; }        
    public string TimeIn { get; set; }
}

Unfortunately CrystalReport does not support Nullable<T> and both DateIn and WeightIn fields are nullables.

If it's applicable in your case what you can do is to publish two extra properties that map null to a value, like this:

public double _WeightIn
{
    get
    {
        if (WeightIn == null)
            return Double.NaN;

        return (double)WeightIn;
    }
    set
    {
        if (value == Double.NaN)
            WeightIn = null;
        else
            WeightIn = value;
    }
}

Of course this will make your class pretty "dirty" and unless you're using a model class to pass data to the report this may be a problem. You may consider to add this attribute to hide that property in the VS editor:

[EditorBrowsable(EditorBrowsableState.Never)]

Do not forget that CR will see the "fake null" value ( Double.NaN and DateTime.MinValue ) and because it doesn't know they're special values it'll use them as they are. If this is a problem (or you can't use a proper null value ) then you'll need to change your reports to handle this special cases.

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