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'并键入'DBNull'。”
如果这两列不可见,我如何得到Column Inc和Column Dec的总数?
答案 0 :(得分:0)
您可以改为在数据源上运行计算。如果您的基础源是数据表,则可以枚举数据行或使用table.compute
。
答案 1 :(得分: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