이것이 쉬운 방법 일 것이라고 생각합니다.캐스팅/캐스팅하지 않을 때의 무한 값 오류
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 != ""))
어떤 도움도 좋을 것!
Im 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
어떤 정확한 오류가 발생합니까? 또한 캐스트하기 전에 null을 확인하려고합니다. 바로 가기 평가에서 작업을 수행하려면 – TJHeuvel
(row.Cells [ "Pareto"] .Value! = null)이 가장 먼저 표시되어야합니다. –
정수로 캐스팅 한 후 null을 확인합니다. 먼저 문을 재정렬하여 null을 먼저 확인하십시오. – Broam