#NULL不是Int32的有效值 [英] #NULL is not a valid value for Int32
本文介绍了#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 assigndefectColor.DefectTypeID
to the parameterDefectTypeID
you get an error. Check ifDefectTypeID
is a string or nullable type.
这篇关于#NULL不是Int32的有效值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文