Default DateTime Value in a column

  • Thread starter Thread starter Josh
  • Start date Start date
J

Josh

Hi,

Im creating an in memory DataTable. I have a "dtCreated" column that I
want to be populated with the current date and time when a record is added.
I dont want to code this every time I add a record.

Is there a way to set the defaultValue of the column so that is always
inserts the current date time when a record is added.

I want this to work like a SQL Server column that has "getdate()" as the
default value.

Thanks in advance...
 
Perhaps you might consider implementing DataTable.RowChanged event and
initialize default values there.
 
One simple way to do it is to add it to your table definition. Set
AllowNulls to false, and set the default value of the column to 'getdate()'
(no quotes). The current date will be written to the column of any new
record created.
 
Back
Top