Click here to Skip to main content
15,912,072 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
Hi,
I have declared a time field in db Table as Time(7). How can i insert a data from a Time picker to This, Please explain if anyone knows
Posted
Comments
OriginalGriff 24-Oct-13 1:56am    
Downvote countered

1 solution

Depending on what time picker you use (and I have no idea) you may need to convert it's output to a TimeSpan and then pass that: TimeSpan maps directly to/from an SQL Time field.
C#
TimeSpan theTime = DateTime.Now.TimeOfDay;
using (SqlConnection con = new SqlConnection(strConnect))
    {
    con.Open();
    using (SqlCommand com = new SqlCommand("INSERT INTO myTable (theTime) VALUES (@TIME)", con))
        {
        com.Parameters.AddWithValue("@TIME", theTime);
        com.ExecuteNonQuery();
        }
    }
 
Share this answer
 
Comments
id-athul 24-Oct-13 7:21am    
Thanks a lot
OriginalGriff 24-Oct-13 7:32am    
You're welcome!
harsha11111 7-Jul-21 1:15am    
I want to add present time to existing time in "theTime" column.
Please explain
OriginalGriff 7-Jul-21 3:43am    
And?
What have you tried?
What does it do that you didn't expect, or not do that you did?
What have you tried to do to find out why?
Are there any error messages, and if so, where and when? What did you do to make them happen?

This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
Use the "Improve question" widget to edit your question and provide better information.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900