This is actually not a question, but I want to share what I realized when I was doing some projects using DataGridView. I was a bit confused on what I should use for the cells whenever I check the value of a DataGridCell (e.g.
Before I usually do it like this:
If Not String.IsNullOrEmpty(dgv.Rows(0).Cells(0).Value.toString()) Then Dim str As String = dgv.Rows(0).Cells(0).Value.toString() End If
But I sometimes get an error when the value of the cell is nothing. So I realized that instead of using toString(), I should have been using CStr().
If Not String.IsNullOrEmpty(CStr(dgv.Rows(0).Cells(0).Value)) Then ...
But for datatable, it is the opposite.
CStr(dt.Rows(0).Items(0)) would generate an error if its value is DBNull. So instead of using CStr(), toString() is the correct method to use :
dt.Rows(0).Items(0).toString() I was really confused before as to which to use in DataTable and in DataGridView. So I hope this will help someone in using DataTable and DataGridView.