没有为类型dbnull定义运算符'*' [英] Operator '*' is not defined for type dbnull
本文介绍了没有为类型dbnull定义运算符'*'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hii,我想要乘以datagridview cells值。但当我执行程序时,它显示"运算符'*'未定义为类型Dbnull,而类型DbNull"
Hii, i am tring to multiply datagridview cells value. but when i execute prograam it show " Operator '*' is not defined for type Dbnull and for type DbNull"
这里是我的代码
Private Sub DataGridView1_CellValueChanged(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellValueChanged
For row As Integer = 0 To DataGridView1.Rows.Count - 1
If IsDBNull(DataGridView1.Rows(row).Cells(7).Value) Then
Console.WriteLine("Null detected")
Else
Console.WriteLine(DataGridView1.Rows(row).Cells(7).Value)
Me.DataGridView1(7, e.RowIndex).Value = Me.DataGridView1(5, e.RowIndex).Value * Me.DataGridView1(6, e.RowIndex).Value
'Me.DataGridView1(7, e.RowIndex).Value = purchase
End If
Next
End Sub
任何人都可以帮助解决这个问题。
can anyone help to solve this problem.
谢谢&问候
推荐答案
试试
For row As Integer = 0 To DataGridView1.Rows.Count - 1
If DataGridView1.Rows(row).Cells(7).Value IsDbNull.Value Then
Console.WriteLine("Null detected")
Else
Console.WriteLine(DataGridView1.Rows(row).Cells(7).Value)
Me.DataGridView1(7, e.RowIndex).Value = Me.DataGridView1(5, e.RowIndex).Value * Me.DataGridView1(6, e.RowIndex).Value
'Me.DataGridView1(7, e.RowIndex).Value = purchase
End If
Next
End Sub
您也可以选择严格选项。您应该将您的值转换或转换为数字类型(IE:int32,double等)
also you may wish to turn option strict on. You should be casting or converting your values as numeric type (IE: int32, double, etc)
这篇关于没有为类型dbnull定义运算符'*'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文