Click here to Skip to main content
15,882,017 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am trying to populate textbox on windows application from database.

The stored procedure pulls data using datareader. Data looks fine when I execute stored procedure on SQL server management studio.

But when I am trying to populate from the application its not getting same result.

I appreciate all help.

Thanks

txtovrts.Text = dr["lst_mod_dt"].ToString();
// returns date only
txtovrts.Text = Convert.ToDateTime(ds["lst_mod_dt"].ToString("MM/dd/yyyy hh:mm:ss");
//returns correct date but time stamp is always returned as 12:00:00(which is incorrect)
Posted
Comments
BillWoodruff 27-Jan-16 20:19pm    
Try inserting this line of code:

var dresult = dr["lst_mod_dt"];

Put a break-point after it; when you hit the break-point, hover over 'dresult and examine its internal contents, looking at the values of its internal state. Use the Command Window to further assist your exploration.

Clarify your question based on what you observe.
koolprasad2003 27-Jan-16 23:38pm    
It looks you have fetch 'lst_mod_dt' date only, does you have store time in database, cause default time is 12:00:00 always. Confirm your date columns contains time also.
Sinisa Hajnal 28-Jan-16 2:50am    
If it is date variable instead of datetime it will not have time component. This is relevant for DB2 (you didn't specify which database you use)

OTher then that, don't convert.ToDateTime has an overload that accepts object. Simply use Convert.ToDateTime(ds["ls_mod_dt"])

1 solution

Most probably it is precision issue. Same query is resolved (with detailed answer) here:

c# - DateTime from SQL Server with timezone - Stack Overflow[^]

So you need to use:
C#
DateTime dt = (DateTime) reader["lst_mod_dt"];
 
Share this answer
 
v2

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