user3236873
user3236873

Reputation: 3

retrive empty or null value of date from datagridview ? VB Net

        Dim datagrid1 As Date = Nothing
        Dim remaning1 As DateTime = DateTime.Now
        Dim answer1 As Integer = Nothing


        datagrid1 = DataGridView2.Rows(0).Cells(4).Value

if datagridview value is empty then there is an error. How to rectify this issue.

Upvotes: 0

Views: 992

Answers (2)

Nayon
Nayon

Reputation: 37

Do a check whether the value is null and set the value accordingly:

            If Not IsDBNull(DataGridView2.Rows(0).Cells(4).Value) Then
                datagrid1.Value = DataGridView2.Rows(0).Cells(4).Value
            End If

Upvotes: 1

IronAces
IronAces

Reputation: 1883

The question is a bit unclear... but I think you want to check that the value in the DataGridView is a valid date... If so, use the below

If TypeOf(DataGridView2.Rows(0).Cells(4).Value) Is Date Then
   'Logic here...
End If

Upvotes: 0

Related Questions