Click here to Skip to main content
15,885,914 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello,

I'm having some problems with selecting SQL Time value from DataBase into DateTimePicker which has "Time" format.

C#
            SqlConnection conn = new SqlConnection();
            conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ERS"].ConnectionString;
            string query = "select * from Reyestrator where guid = '" +guid+ "'";
            SqlCommand cmd = new SqlCommand(query, conn);
            SqlDataReader dbr;
            conn.Open();
            dbr = cmd.ExecuteReader();
            while (dbr.Read())
            {               
                dateTimePicker1.Value = Convert.ToDateTime(dbr["DataZgloszeniaZapotrzebowania"]);
.....
                comboBox7.Text = dbr["Forma"].ToString();
                dateTimePicker5.Value = Convert.ToDateTime(dbr["RealnyCzas"]);
                checkBox1.Checked = Convert.ToBoolean(dbr["DaneWrażliwe"]);
....
            }
            conn.Close();


The Field I'm having problems with is "RealnyCzas" placed in dateTimePicker5.

Any ideas how could I do this?
Posted
Comments
Sharmanuj 31-Jul-14 4:38am    
What is the error/issue you are getting?
Jakub Naduk 31-Jul-14 4:48am    
The value is not inserted into picker.
Sharmanuj 31-Jul-14 4:58am    
you should try this

DateTime currentDateTime;
currentDateTime = Convert.ToDateTime(dbr["RealnyCzas"].ToString());

dateTimePicker5.Value = currentDateTime ;

1 solution

Right click on dateTimePicker5 control and change its properties as below
C#
dateTimePicker5.CustomFormat = "dd-MMM-yyyy hh:mm:ss tt";//Or Whatever format you want.
dateTimePicker5.Format = Custom;

I hope it works.
 
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