SQL DateTime and DSropDown Index Question to get both values...

Seems simple enuff.  Fill out the form, populate the record okay, EXCEPT that I am not getting the time on the DateTime  field in my SQL table.  Date is fun but Time is Zeroes. (according to the Management Studio tool)

        protected void btnSubmit_OnClick(object sender, EventArgs e)
            if (Page.IsValid)
                SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString1"].ConnectionString);
                // Create Command object
                SqlCommand command = conn.CreateCommand();

                    // Open Connection

                    // Create INSERT statement with named parameters
                    command.CommandText = "INSERT INTO ContactUs (ContactUs_ID, ContactUs_first_name, ContactUs_last_name, ContactUs_date_entered, ) VALUES (@ContactUs_ID, @ContactUs_first_name, @ContactUs_last_name, @ContactUs_date_entered)";
                    command.CommandTimeout = 15;
                    command.CommandType = CommandType.Text;

                    // Add Parameters to Command Parameters collection
                    command.Parameters.Add("@ContactUs_ID", SqlDbType.VarChar, 6);
                    command.Parameters.Add("@ContactUs_first_name", SqlDbType.VarChar, 30);
                    command.Parameters.Add("@ContactUs_last_name", SqlDbType.VarChar, 30);
                    command.Parameters.Add("@ContactUs_date_entered", SqlDbType.DateTime2);

                    // Fill Parameters from the controls and get the date
                    command.Parameters["@ContactUs_ATTUID"].Value = userID.Text;
                    command.Parameters["@ContactUs_first_name"].Value = userFirstName.Text;
                    command.Parameters["@ContactUs_last_name"].Value = userLastName.Text;
                    command.Parameters["@ContactUs_date_entered"].Value = DateTime.Today;
                    // Display error
                    lblMessage.Text = e.ToString();
                    lblMessage.Visible = true;
                    // Close Connection
                    lblMessage.Text = "Your message has been saved";
                    lblMessage.Visible = true;

Open in new window

Oh, tried this also....

                    DateTime date1 = new DateTime();
                    date1 = DateTime.Today;
                    command.Parameters["@ContactUs_date_entered"].Value = date1;

any HEPL would be appreciated!!   :D

Bob BenderAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ste5anSenior DeveloperCommented:
Ahm, yes. It's DateTime.Now instead of DateTime.Today.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nemws1Database AdministratorCommented:
You could just use GETDATE() in your query instead (also, you have a trailing comma in your field list before the close paren before "VALUES", I've removed it here):

command.CommandText = "INSERT INTO ContactUs (ContactUs_ID, ContactUs_first_name, ContactUs_last_name, ContactUs_date_entered) VALUES (@ContactUs_ID, @ContactUs_first_name, @ContactUs_last_name, GETDATE())";

Open in new window

Bob BenderAuthor Commented:
Well, it HAS been a long time away from all those options.  So simple, that a old time gets lost.   Testing now....
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.