SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Date issues
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

android.sm
Starting Member

36 Posts

Posted - 07/16/2011 :  10:50:44  Show Profile  Reply with Quote
(1) why doesn't my date field auto populate the current system time when creating a new record? i use(getdate()) in sql server (default value or binding column property. the date's datatype is datetime.

(2) my website is hosted in US - thus capturing US time. Ex:

UK: 2011-07-15 21:05:30.630
US: 2011-07-15 13:05:30.630

i need a way to take current time and - 8hours hence it becomes UK time.

jeffw8713
Aged Yak Warrior

USA
798 Posts

Posted - 07/16/2011 :  11:21:56  Show Profile  Reply with Quote
What is the code you are using to insert the new row? If you are specifying anything for that column, the default value will not be used.
Go to Top of Page

android.sm
Starting Member

36 Posts

Posted - 07/16/2011 :  11:38:22  Show Profile  Reply with Quote
hey,

i'm not writing any code for it and not passing in any values. i simply want it to auto populate the column when a record is created.
Go to Top of Page

android.sm
Starting Member

36 Posts

Posted - 07/16/2011 :  14:00:43  Show Profile  Reply with Quote
ok i just noticed that it does create the time /date when i manually insert a new record.

my code to create the record is using c#

DatabaseLayerDataContext db = new DatabaseLayerDataContext();

            try
            {
                Comment comments = new Comment();
                comments.Title = ddlTitle.SelectedValue;
                comments.FirstName = txtFirstName.Text;
                comments.LastName = txtLastName.Text;
                comments.Message = txtMessage.Text;
                db.Comments.InsertOnSubmit(comments);
                db.SubmitChanges();
                lblDisplayMessage.Text = "Thank you for your message. We will deal with this as soon as possible.";
            }
            catch (Exception err)
            {
                lblDisplayMessage.Text = "An error occurred - please try again later. Thank you for your patience.";
                Console.WriteLine("{0}", err.Message);
            }
Go to Top of Page

android.sm
Starting Member

36 Posts

Posted - 07/16/2011 :  19:03:41  Show Profile  Reply with Quote
fixed. issue was the code. linq to sql in .net doesn't support auto generated values in db other than identity seed.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000