vb.net - Conversion from type 'DBNull' to type 'Date' is not valid on tryparse -
i attempting datetime.tryparse
date-formatted string, new column created part of dataview
table. getting error when code runs conversion type 'dbnull' type 'date' not valid.
this line of code:
datetime.tryparse(dr("ix_articlestartdate"), dr("nstartdate"))
and these values in watch when errors out.
+ dr("ix_articlestartdate") "2015/3/11" {string} object + dr("nstartdate") {} object
i under impression tryparse
return null
value if fails convert datatypes. there should doing different convert string datetime
datatype?
dr instantiated datarow
dim dr datarow = dv0.table.rows(i)
vb implicitly try's cast dbnull value datetime, since method signature of datetime.tryparse is
public shared function tryparse(s string, byref result date) boolean
which fails. can use variable instead:
dim startdate datetime if datetime.tryparse(dr("ix_articlestartdate").tostring(), startdate) dr("startdate") = startdate end if
Comments
Post a Comment