2

I am connecting to a database using VS2008 DataSets. One of the Tables within the database contains a DateTime Column that allows nulls (i.e. Type: DateTime?)

MSDN Datasets categorically states:

The Nullable or Nullable structure is not currently supported in the DataSet.

However on the MSDN site for TableAdapters states that TableAdaters CAN support Nullable Types:

The TableAdapters support nullable types Nullable(Of T) and T?. For more information on nullable types ... For more information on nullable types in C#, see Using Nullable Types (C# Programming Guide).

I'm confused!

In the DataSet Designer I have set the offending Column's property to 'AllowDBNull=True' but whenever I run a TableAdapter Query that returns a null DateTime (SELECT * FROM UDF) I get the following Exception: "ArguementOutOfRangeException: Year, Month, and Day parameters describe an un-representable DateTime."

One idea I had was to change the type of the Column to System.Object to correctly handle the null values and then I can do the conversions in my own code, however, I still get the same exception being raised.

This question suggests how to deal with the nulls once the query has returned, however I can't get the query to return.

How can I modify the TableAdapter and/or Dataset to allow me to run a query on the Table that can deal with the nulls in the database?

Community
  • 1
  • 1
TK.
  • 46,577
  • 46
  • 119
  • 147
  • Better show the query. It ought to just work. – H H Nov 18 '10 at 10:20
  • I think the query works, I imagine the issue is with the auto-generated TableAdapter/Dataset that cant interoperate the null DateTime and just raises an exception. – TK. Nov 18 '10 at 11:04
  • No, generated datatables can handle nullable columns just fine. – H H Nov 18 '10 at 12:23
  • Yes ... sorry, I should have clarified that when adding the query. – TK. Nov 19 '10 at 08:06

1 Answers1

0

The solution I found was to use the TO_CHAR() Oracle function and tell the Table Adapter to expect a string value

SELECT to_char(NULL_DATE_FIELD,'dd/mm/yyyy HH24:MI:SS') FROM *

This means that there is some conversion that needs to happen in the using code. Not ideal though!

TK.
  • 46,577
  • 46
  • 119
  • 147