Setting DefaultValue for Datetime
In SQL Server Express (Visual Studio 2010), I would like to set the default datetime field to the creation date & time for the record. Numerous posts indicate I should set the DefaultValue in properties to GetDate(). But this throws an error "Property Value is not valid - The string was not recognized as a valid DateTime. There is an unknown word starting at index 0.
Re: Setting DefaultValue for Datetime
Show us the insert statement. Have you created a default for the columns? Are you just doing this in the SQL Statement?
Re: Setting DefaultValue for Datetime
I am not doing it in code. I am just trying to set it in the Properties using the 'View Designer' (shows the relational view with the tables and fields). I select the field, which is a datetime, and try to set the DefaultValue property.
Re: Setting DefaultValue for Datetime
I don't use the UI I do this with SQL code in SSMS like this:
sql Code:
ALTER TABLE tableNameHere
ADD CONSTRAINT [df_SomeNameHere] DEFAULT (GETUTCDATE()) FOR [ColumnNameHEre];
END
Re: Setting DefaultValue for Datetime
Thanks for the guidance. I know I can do it that way, but I would like to do it in the UI.