Default DateTime Value in a column

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...
 
M

Miha Markic [MVP C#]

Perhaps you might consider implementing DataTable.RowChanged event and
initialize default values there.
 
D

David Veeneman

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.
 

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