DBNull in DataGrid

A

Agnes

in the datagrid, if the user use backspace to delete it . Then I will got an
dbnull error .
How.
In the datatable columnchanged event.
Private Sub dtGLJnDetail_ColumnChanged(ByVal sender As Object, ByVal e As
System.Data.DataColumnChangeEventArgs) Handles dtGLJnDetail.ColumnChanged
If IsDBNull(Me.dgDetail(dgDetail.CurrentCell.RowNumber,
dgDetail.CurrentCell.ColumnNumber)) = True Then
Me.dgDetail(dgDetail.CurrentCell.RowNumber,
dgDetail.CurrentCell.ColumnNumber) = "" <--- It can solve BUT....
End If

(A) IF e.row("acctcode") = "" then Messagebox.show("Account Code Cannot
Be Blank!") <--- It doesn't work .
(B) Dim strAcctCode as string
strAcctCode = e.Row("acctcode")
If strAcctCode.Trim.Length = 0 Then Messagebox.show("Account Code
Cannot Be Blank!") <-- It works.

Why(A) doesn't work . my datagrid got 10 columns. If I use approach (B) ,
it seems very stupid.
Does anyone got other idea ? Thanks a lot
 
C

Cor Ligthert

Agnes,

There is a difference between
a = ""
and
a Is DbNull.Value

The last references to the object DBNull.Value

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top