I am using a TableAdapter to insert data into an MS Access Database and I am getting an Invalid Cast Error when I try and insert a record that has a DBNull value for a date field. The Insert is being populated by the records of another table. I am using the ISDBNull function to check for DBNull and if true, replace the DBNull with 01/01/1900 as the date. So I have two questions:
1. What is wrong with this statement that it doesn't work: (as part of my TableAdapter.Insert call)
IIf(IsDBNull(drRowEmployees("CheckWritten")), "#01/01/1900#", drRowEmployees("CheckWritten")),
IsDBNull(drRowEmployees("CheckWritten")) = true (verified with MsgBox)
accepts "#01/01/1900#" if I hard-code it
Database field is defined as DateTime and allows Nulls
2. What I really want is if the date field is Null to keep it Null but I can't seem to insert a Null value into the table even though the field is setup to allow null values. Is there a way to do this?
Any help would be greatly appreciated!