![](/img/trans.png)
[英](SQL) Efficient way of replacing of NULL values in DataGridView?
[英]DataGridView Replacing Null Value
我正在尝试在VB中的datagridview中替换空值。 正在从访问数据库读入数据。 每次运行它时,都会出现与“ System.NullReferenceException”相关的错误。
Sub dataGridView1_CellFormatting(ByVal sender As Object, _
ByVal e As DataGridViewCellFormattingEventArgs) _
Handles DataGridView1.CellFormatting
If e.ColumnIndex = Me.DataGridView1.Columns(7).Index Then _
' AndAlso (e.Value IsNot Nothing) Then
With Me.DataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex)
If e.Value.Equals("") Then
e.Value = "very bad"
End If
End With
End If
End Sub
任何有关这个问题的帮助将不胜感激!
您需要检查实际的数据库调用。 您可以检查是否有任何字段为Null
并在那里替换它们。 那么你不必在代码中处理它们......
IIF(ISNULL(yourcolumn),'', yourcolumn)
这将检查该列是否为null
,如果是,则将其替换为空字符串,否则它将返回值...
试试IsDBNull
:
Dim abc As Integer
abc= IIf(IsDBNull(DGVInvoice.Rows(max).Cells(3).Value) = True, 0, DGVInvoice.Rows(max).Cells(3).Value)
DGVInvoice
是您的DataGrid, max
是您的最大行号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.