2017-11-07 3 views
-1
For i As Integer = 0 To DataGridView1.RowCount - 1 
     fundwith += DataGridView1.Rows(i).Cells("Withdrawal").Value 
     trans += DataGridView1.Rows(i).Cells("Trans").Value 
     meal += DataGridView1.Rows(i).Cells("Meal").Value 
     rep += DataGridView1.Rows(i).Cells("Rep").Value 
     meet += DataGridView1.Rows(i).Cells("Meet").Value 
     misc += DataGridView1.Rows(i).Cells("Misc").Value 
     oth += DataGridView1.Rows(i).Cells("Others").Value 
     inc += DataGridView1.Rows(i).Cells("Inc").Value 
     dec += DataGridView1.Rows(i).Cells("Dec").Value 
    Next 

이 오류가 발생합니다. 'Double'유형에 'Operator'+ '가 정의되어 있지 않으며'DBNull 'DataGridview의 열이 표시되지 않는 경우 합계를 계산하십시오.

두 컬럼이 보이지 않으면 어떻게 Inc Inc와 Column Dec의 합계를 구합니까?

+0

는 &'dec' 열이 실제로 데이터하지만 눈에 보이지 않는를 포함하거나이 가능 단지들에 DBNull이이 inc''합니까 열? –

+0

감사합니다. 이제 나는 내 실수를 안다. 값이 null이므로 그 이유는 오류입니다. – elaine8s

+0

DBNull을 검사하여'Double'의 디폴트 값 (0) 인'inc + = CheckDBNull (DataGridView1.Rows (i) .Cells ("Inc") .Value)'와 자동으로 변환 할 수 있다고 생각합니다. –

답변

0

대신 데이터 소스에서 계산을 실행할 수 있습니다. 원본 소스가 데이터 테이블 인 경우 데이터 행을 열거하거나 table.compute을 사용할 수 있습니다.

0

액세스 기본 DataRow ...

Dim drw as DataRow = DirectCast(DataGridView1.Rows(i).DataBoundItem, DataRowView).Row 

그런 다음

fundwith += CDec(drw("Withdrawal")) 'replace CDec with whatever type conversion you need 
+0

확실히 틀린 것은 아니지만 'DataRowView'에서 'DataRowView'에 액세스 할 필요가 없습니다. 'DataRowView'는 동일한 정보를 제공 할 수 있기 때문입니다. – jmcilhinney