Click here to Skip to main content
15,891,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
mysql table as below

day start_time
1 08:00
2 08:00

I want to display the star_time in datetimepicker and value got updated if the user change time in datetimepicker.

What I have tried:

C#
private void ShowData()
{
    /*retrieve from database*/
    dataTbl = new DataTable();
    DALWorktime dalWorktime = new DALWorktime();
    dataTbl = dalWorktime.GetWorkTime();


    DateTime dt1 = new DateTime(2016, 3, 28, 8, 0, 0);
    MainWT_dtpicker_startDay1.Value = dt1;
Posted
Updated 28-Mar-16 16:43pm
v2
Comments
VR Karthikeyan 28-Mar-16 13:01pm    
What is your front end? WPF or Windows Forms?
Member 12421315 28-Mar-16 13:03pm    
Windows Form
VR Karthikeyan 28-Mar-16 13:17pm    
Do you want to set datetime dynamically from database in DateTimePicker?
Member 12421315 28-Mar-16 13:30pm    
yes
VR Karthikeyan 28-Mar-16 22:43pm    
See solution 1

1 solution

Hi, just modify your code like following,
C#
dataTbl = new DataTable();
DALWorktime dalWorktime = new DALWorktime();
dataTbl = dalWorktime.GetWorkTime();
//Consider am using start time of Day 1
string StartTime = dataTbl.Rows[0][1].ToString().Trim();
string[] HourAndMinute = StartTime.Split(':');
int Hour = Convert.ToInt32(HourAndMinute[0]);
int Minute = Convert.ToInt32(HourAndMinute[1]);
int Seconds =  0; //default

int Year = DateTime.Now.Year;
int Month = DateTime.Now.Month;
int Day = DateTime.Now.Day;

DateTime dt1 = new DateTime(Year, Month, Day, Hour, Minute, Seconds);
MainWT_dtpicker_startDay1.Value = dt1;
 
Share this answer
 

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