Question : System.Date type in a dataset?

i'm trying to do :

StatementTable.Columns.Add("statement_date", Type.GetType("System.Date"))

Dim TheDataRow As DataRow

TheDataRow = StatementTable.NewRow()

TheDataRow("statement_date") = Date.Now

but at the Columns.Add line I get the error :

---
An unhandled exception of type 'System.ArgumentNullException' occurred in system.data.dll

Additional information: 'dataType' argument cannot be null.

Unhandled Exception: System.ArgumentNullException: 'dataType' argument cannot be null.
---

Changing that to System.DateTime solves the exception, but not the problem. I don't want the entire time string, but I do need it in a date variable. I *only* want the date, is there any way to make that work? I'd like to avoid having to put formatting on it as this will be used internationally where the users preferred date format might not be what I would choose (and hard-code in).

Thanks!


Answer : System.Date type in a dataset?

If you want the data stored as a date then I don't think you have any option other than to use DateTime.  The "permitted" list of datatypes is here (for .NET 2003)

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatadatacolumnclassdatatypetopic.asp

It's the same in .NET 2005.

The disadvantage of doing this is that it does store data (the time) that you don't want and mean that, for the purposes of your app, you may need extra coding to strip times off for display or comparison purposes.

The advantage of using DateTime - rather than, e.g., a string which you hard code - is that it will be represented locally in accordance with the local culture.  So the DateTime representation of 1 April 2005 will show as 01/04/2005 on a system with UK culture settings but 04/01/2005 on a system with US culture settings.  But a string of 01/04/2005 (or whatever) will be show - in date terms - as 1 April 2005 on a UK system and 4 January 2005 on a US system.

It's a perennial problem.  Here's another question on the same general theme

http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21538974.html

Roger
Random Solutions  
 
programming4us programming4us