Hi, I wants to ask how to convert DBNull to Date type?
For Each row As DataRow In dt.Rows i = 0 Dim array As Object = row.ItemArray Dim a As String If array(i + 10) IsNot Nothing Then a = CDate(array(i + 10)).ToString("yyyy-MM-dd hh:mm:ss") Else array(i + 10) = DBNull.Value a = array(i + 10) End If SQLStr2 = "INSERT INTO ScannedPartNoTbl (ScannedTime)" & _ " VALUES ('" & _ SQLStrCmd.ReplaceStr(a) & "')" Next
array(i + 10) is datetime type, in the program above, if the Datetime column contains items, it still can run. However, when it loops to a row where the Datetime column does not have value of datetime (or the column is null), then an error " Conversion from type 'DBNull' to type 'Date' is not valid" is occured. I tried to use the if statements as program above but it seems like cannot works.
Anyone have solution for this problem?
Edited 5 Years Ago by leo88: n/a