Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8249575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:35:36+00:00 2026-06-07T23:35:36+00:00

I’m have a Windows Form with 2 datetimepicker controls: one for date and a

  • 0

I’m have a Windows Form with 2 datetimepicker controls: one for date and a separate datetimepicker control for time. Both of these controls are bound to the same column in a database and the controls have different property names (i.e., dateEdit and timeEdit) and different formats (i.e., Long and Time).

Here are my problems/questions:

  1. The timeEdit picker ignores whatever seconds are in the database entry and sets the time seconds to “00”, as in “2:34:00”, even though the database entry (trimmed to time for this illustration) is “14:34:31.891123 -04:00”. How can I get the seconds to correctly display?
  2. Whenever I edit the seconds in the timeEdit picker from “00” to (for example) “15”, as in “2:34:15”, the picker resets the seconds to “00” before passing the value to the next function. How do I pass the correct seconds value?
  3. I’d like to edit the milliseconds on the time. Is it best for me to bind the trimmed milliseconds (using DATEPART) to a text box? Will I need to convert or cast the milliseconds to a char or string in order to correctly display them in a text box?

Thanks for any help!

Code to trigger the edit form:

    private void timeDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
    {
        try
        {
            if (e.ColumnIndex == 5)
            {
                EditTime editForm = new EditTime((Guid)timeDataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value);

                editForm.StartPosition = FormStartPosition.CenterScreen;
                editForm.ShowDialog();
                editForm.Close();
            }
        }
        catch (Exception ex)
        {
            string msg = "Error: ";
            msg += ex.Message;
            throw new Exception(msg);
        }
    }

Code for the form:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;

    namespace StatusManager
    {
        public partial class EditTime : Form
        {
            private Guid calendarId;

            public EditTime()
            {
                InitializeComponent();
            }

            public EditTime(Guid Id)
            {
                InitializeComponent();
                calendarId = Id;
            }

            public string GetConnectionString()
            {
                var connString = ConfigurationManager.ConnectionStrings["StatusManager.Properties.Settings.StatusConnectionString"].ConnectionString;
                return connString;
            }

            private void UpdateCalendarItem(string dateEdit, string timeEdit, string note)
            {
                var conn = new SqlConnection(GetConnectionString());

                const string UpdateStatusSql = @"UPDATE dbo.statuses SET
                calendarTime = @timeOffset
                notes = @note 
                WHERE PK_calendarUID = @PK_calendarUID";

                try
                {
                    SqlCommand cmd = new SqlCommand(UpdateSql, conn);
                    var param = new SqlParameter[3];

                    param[0] = new SqlParameter("@PK_calendarUID", calendarId);

                    //Convert date(s) to correct format
                    string dateTimeCombined = dateEdit + " " timeEdit;
                    DateTime timeConverted = Convert.ToDateTime(dateTimeCombined);
                    DateTimeOffset timeOffset = new DateTimeOffset(timeConverted);

                    param[1] = new SqlParameter("@timeOffset", timeOffset);
                    param[2] = new SqlParameter("@note", note);

                    foreach (SqlParameter t in param)
                    {
                        cmd.Parameters.Add(t);
                    }

                    conn.Open();
                    cmd.CommandType = CommandType.Text;
                    cmd.ExecuteNonQuery();
                }
                catch (SqlException ex)
                {
                    string msg = "Error updating 'calendarItems': ";
                    msg += ex.Message;
                    throw new Exception(msg);
                }
                finally
                {
                    conn.Close();
                }          
            }

            private void editTimeButton_Click(object sender, EventArgs e)
            {
                UpdateCalendarItem(dateEdit.Text, timeEdit.Text, notes.Text);

                this.Close();
            }

            private void EditTime_Load(object sender, EventArgs e)
            {
                this.locationsTableAdapter.Fill(this.locationsDataSet.locations);
                this.calendarTableAdapter.FillById(this.calendarDataSet.calendarItems, calendarId);
            }
        }
    }

Code for instantiating the datetimepicker:

    this.timeEdit.CustomFormat = "";
    this.timeEdit.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.calendarBindingSource, "calendarTime", true));
    this.timeEdit.Format = System.Windows.Forms.DateTimePickerFormat.Time;
    this.timeEdit.Location = new System.Drawing.Point(385, 30);
    this.timeEdit.Name = "timeEdit";
    this.timeEdit.ShowUpDown = true;
    this.timeEdit.Size = new System.Drawing.Size(89, 20);
    this.timeEdit.TabIndex = 2;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T23:35:38+00:00Added an answer on June 7, 2026 at 11:35 pm

    Problem solved but I’m not exactly sure how. Here’s what I did:

    1. In calendarDataSet, I updated both queries (Fill,GetData and FillById,GetDataBy (@ID)) to select calendarTime as CONVERT(VARCHAR(12), calendarTime, 114) AS calHoursMinsSec
    2. In essence, I created created a new column with the hours, minutes, seconds, and milliseconds
    3. On the form, I added a textbox and bound the textbox to calHoursMinsSec

    Note: My previous attempts to convert the datetime to a varchar to were unsuccessful no doubt due to operator error.

    Once I saved the form, the binding seemed to stick and I was able to pass the relevant variables to the update function

    Thanks for everyone’s input! I appreciate the guidance and suggestions!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a text area in my form which accepts all possible characters from
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.