Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Feb 26, 2012 08:12 AM by bojangles
Feb 20, 2012 03:37 AM|LINK
Does anyone know why I have a Datetime field set to getdate() by default in an SQL Server 2008 R2 database but it's inserting NULL. As far as I know that’s all I need to do???
I think I have a ghost in the machine!
Feb 20, 2012 03:42 AM|LINK
it should work... how r u setting default value?
ALTER TABLE TableName
ADD DEFAULT GETDATE() FOR ColumnName
hope this helps...
Feb 20, 2012 03:53 AM|LINK
But i'm doing all this from inside VWD and my hosting company has a GUI for all of this too.
I must have built 500 databases in my life and never had to CRUD on via SQL.
Feb 20, 2012 04:35 AM|LINK
how are you inserting data in table row? r u seding the dataset updates from dataadater?
u might have datetime field included in there....
may be posting the code would help
Feb 20, 2012 09:46 PM|LINK
It’s a WCF and I’m now inserting the date with the other fields with the following code. I thought I could simply make the CommuniqueDate field by default set its self to the server date with getdate() when a new record is inserted but it doesn’t seem to
public bool putCommunique(string communiqueIMEI, string communiqueType)
Communique communique = new Communique
CommuniqueIMEI = communiqueIMEI,
CommuniqueType = communiqueType,
CommuniqueDate = DateTime.Now
Feb 24, 2012 07:00 AM|LINK
Have you tried to test that whether DateTime.Now has passed value to CommuniqueDate or not? You could use try...catch to catch that error.
ObjectContext.AddObject Method :http://msdn.microsoft.com/en-us/library/system.data.objects.objectcontext.addobject.aspx
Feb 26, 2012 08:12 AM|LINK
Thanks Chen Yu,
I’ve had a look through some Microsoft auto generated code, e.g.. the code generated for membership and the aspnet.mdf when you create a new MVC site and it looks like MS don’t rely on SQL Server adding the date time automatically. So I will do it this way
from now on.