Entity Framework | leading, pad, trailing zeros

tomas7470

New member
Joined
May 7, 2014
Messages
4
Programming Experience
3-5
The software uses Entity Framework with SQL Server.

I've ran into some weird problem while creating a large scale software..
I used Maskedtextbox with the format: 00:00 and DateTimePicker, pulled out from the EF (SQL) the date time as date.
In the SQL DB the date time shows "#00/00/0000 00:00#" this is what i did:
VB.NET:
StartWork.Text = Can.DateStartWork
Hour_Start_Work.Text = Can.DateStartWork.ToString.Substring(11, 5)

There is one particular PC that pull out the data with no leading, trailing or pad zeroes(0) (e.g: for the time: 10:00 I get 00:0_ the masked isnt full)

Any ideas?

Thanks
Tom :)
 
Your code is relying on the default system format and that could be anything on any given system. If what you actually want is the time portion in 24-hour format then that is what you should get:
Hour_Start_Work.Text = Can.DateStartWork.ToString("HH:mm")
By specifying the format explicitly, you avoid any differences between systems.
 
What's the data type of DateStartWork? If the data represents dates/times then it should be DateTime and that's what I was assuming. That error message suggests otherwise. What is the data type of the corresponding column in the database too?
 
Thanks i fixed it with value:
VB.NET:
 Hour_Start_Work.Text = Can.DateStartWork.Value.ToString("HH:mm")

do u know what is the format for Date?
VB.NET:
StartWork.Text = Can.DateStartWork.Value.ToString("dd/mm/yyyy")
??
 
Back
Top