Design issue: Handling null datetimes from legacy databases.


B

B. Chernick

I'm writing a demo website in VB/Dot Net 2.0. The database is SQL 2000 and
the design is at least partially legacy. (And this is the first real web
work I've done in 2.0. All previous work was in 1.1) It is my intent to
stay as close to defaults as possible: i.e. using the most generic techniques
possible with as little coding as possible.

My existing database table has some datetime field values that are null. I
have a page with a detailsview bound to a record in that table. The
datetime fields on my webpage are templates. The read-only screen has no
problem displaying the record, but when I hit the Edit link, the page crashes
with the message: 'Conversion from type 'DBNull' to type 'Date' is not
valid.' So far I have not been able to intercept this in VB code.

Apparently it is useless to set the field's xsd default property to
something like '1/1/1900' or '1/1/1753'. I still get the crash. Also I
cannot set the NullValue property to anything other than (Throw Exception)
when the field is a datetime.

I'm getting the impression from my reading that the best approach is to not
permit null datetimes in the first place and that I should simply revise the
database table.

Suggestions?
 
Ad

Advertisements

B

B. Chernick

Thanks but so far I don't get it. I simply dragged a table onto the xsd and
bound it to a detailsview with almost no coding. Is this type of code (the
c-sharpcorner example) supposed to be put in the xsd's code behind? The xsd
itself can't handle nullable declarations.
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top