Skip to main content
 首页 » 编程设计

转换/不转换时 C# 无限值错误

2024年02月23日20artech

我认为这会很简单,我想我遗漏了一些东西。

if (((int)row.Cells["Pareto"].Value <= 50) && (row.Cells["Pareto"].Value != null)) 

这段代码给我的错误是当转换时不能是无限的数字。

我也试过:

if (((int)row.Cells["Pareto"].Value <= 50) && ((string)row.Cells["Pareto"].Value != null)) 
if (((int)row.Cells["Pareto"].Value <= 50) && (row.Cells["Pareto"].Value != "")) 

任何帮助都会很棒!

我在 visual studio 10 中使用 C# 使用 winforms。

错误:“从数字转换时,该值必须小于无穷大”

更多代码,如果您感兴趣的话:

foreach (DataGridViewRow row in dataGridView1.Rows) 
        { 
            //countpg 
            //countPg++; 
            pgtothold = Convert.ToSingle(row.Cells["Qty"].Value); 
            countPg += pgtothold; 
 
            //if (((int)row.Cells["Pareto"].Value <= 50) && (row.Cells["Pareto"].Value != null)) 
            if ((Convert.ToDouble(row.Cells["Pareto"].Value)) && ((int)row.Cells["Pareto"].Value <= 50) 
            { 
                //top 50 
                //top++; 
                tempTop = Convert.ToSingle(row.Cells["Qty"].Value); 
                top += tempTop; 
            } 
            else 
                if (((int)row.Cells["Pareto"].Value > 50) && ((int)row.Cells["Pareto"].Value <= 100) && (row.Cells["Pareto"].Value != "")) 
                { 
                    //50-100 
                    tempMidt = Convert.ToSingle(row.Cells["Qty"].Value); 
                    tmid += tempMidt; 
                } 
                else 

请您参考如下方法:

if ((row.Cells["Pareto"].Value != null) && ((int)row.Cells["Pareto"].Value <= 50)) 

我想你想要这个。如果该事物为空,则它不会计算 AND 的其余部分。