#NULL不是Int32的有效值 [英] #NULL is not a valid value for Int32

查看:829
本文介绍了#NULL不是Int32的有效值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private void satelliteComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
    Helper.SetWaitCursor();
    if (satelliteComboBox.SelectedValue != null)
    {
        var satelliteId = Convert.ToInt32(satelliteComboBox.SelectedValue);
        satelliteStatusUserControl.DataSource =
            _satelliteStatusBusinessService.GetSingleSatellite(
                new Dictionary<string, object> { { "SatelliteID", satelliteId } }, true);
        //2012.07.07 get colors for all machine status
        satelliteStatusUserControl.DataSource.DefectColors =
                  _satelliteStatusBusinessService.GetDefectColors().ToList();

        foreach (var defectColor in
                      satelliteStatusUserControl.DataSource.DefectColors)
        {
            MachineStatusCtrl.AddMachineStatusColors(
                         defectColor.DefectTypeID,
                         defectColor.DefectType,
                         defectColor.OEEColor);
        }
        //2012.07.07
        satelliteStatusUserControl.DataBind();
    }
    Helper.SetDefaultCursor();
}



我在beforeColor.OEEColor的foreach循环中收到此错误,因为#NULL不是Int32的有效值



这是AddMachineStatusColors的实现




I am getting this error in my foreach loop at defectColor.OEEColor as #NULL is not a valid value for Int32

Here is the implementation for AddMachineStatusColors

public static void AddMachineStatusColors(int statusColorId, string StatusName, string oeeColor)
{
    MacStatusColors macStatusColor;

    //add dummy colors with unknow till the next defectId so that it will be easy to get color later while painting.
    for(int Index = StatusColors.Count; Index < statusColorId ; Index++)
    {
        macStatusColor = new MacStatusColors();
        StatusColors.Add(macStatusColor);
    }

    macStatusColor = new MacStatusColors();
    macStatusColor.DefectTypeID = statusColorId;
    macStatusColor.DefectType = StatusName;
    macStatusColor.OEEColor1 = ControlPaint.Dark(getColorFromString(oeeColor));
    macStatusColor.OEEColor2 = ControlPaint.Light(getColorFromString(oeeColor));
    StatusColors.Add(macStatusColor);
}





请找我解决方案并提前致谢



please find me the solution and thanks in advance

推荐答案

您不能为整数分配空值。因此,当您将 defectColor.DefectTypeID 分配给参数 DefectTypeID 时,会出现错误。检查 DefectTypeID 是否为字符串或可空类型。
You cannot assign a null value to an integer. Thus when you assign defectColor.DefectTypeID to the parameter DefectTypeID you get an error. Check if DefectTypeID is a string or nullable type.


这篇关于#NULL不是Int32的有效值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆