sql - Trying to convert DBNull into a date without any luck so far. -
i loading value txtbox(driver) our sql database using filled txtbox(car registration) filter.
so able right driver vehicle. each vehicle can have number of people driving in time, using iif clause make sure current driver selected.
i getting error:
operator '>' not defined type 'dbnull' , type 'date'.
i know need convert dbnull date format, struggling so, have tried few things, , far have got to.
dim cdriver new dictionary(of string, object) cdriver.add("registration", txtreg.text) dim currentdriver datatable currentdriver = businessdata.verifierlogic.load("[car history]", cdriver) dim currentdrivername string = "" dim currentenddate datetime each row datarow in currentdriver.rows if datediff(dateinterval.day, row("end_date"), datetime.now) > 0 currentdrivername = row("driver_name") currentenddate = row("end_date") iif(row("end_date") dbnull, "1 jan 1900", row("end_date")) end if next txtdriver.text = currentdrivername catch ex exception msgbox(ex.message) end try
any appreciated
paul
so row("end_date")
nullable? can use datarow
-extension method field
supports nullable types , typed:
for each row datarow in currentdriver.rows dim enddate date? = row.field(of date?)("end_date") if enddate.hasvalue andalso enddate.value > date.now currentdrivername = row.field(of string)("driver_name") currentenddate = enddate.value exit ' otherwise overwriting these variables ' end if next
Comments
Post a Comment