Click here to Skip to main content
15,911,139 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I wanna Bind (9:00 AM) in my text box from Database(Stored as 9:00:00)...Ibind the value like Below


C#
txtGrace.Text = dt.Rows[0]["GraceTime"].ToString("hh:mm tt" );



Return a Stystem.String that represents the current System Object
Error
No overload for method ToString takes 1 argument</pre>
Posted
Updated 18-May-14 19:20pm
v3
Comments
DamithSL 19-May-14 1:28am    
what is the column type of GraceTime?

1 solution

dt.Rows[0]["GraceTime"] returns a variable of Object type. To enable ToString() with formatting parameter you have to convert it to DateTime...
C#
txtGrace.Text = Convert.ToDateTime(dt.Rows[0]["GraceTime"]).ToString("hh:mm tt" );
 
Share this answer
 
Comments
phmani469 19-May-14 1:57am    
Thank u so much......for spending valuable time to solve my problem.............
Kornfeld Eliyahu Peter 19-May-14 2:03am    
You are welcome...
phmani469 19-May-14 2:04am    
Unable to cast object of type 'System.TimeSpan' to type 'System.IConvertible'.
Kornfeld Eliyahu Peter 19-May-14 2:08am    
Oh. So it's not DateTime...
((TimeSpan)dt.Rows[0]["GraceTime"]).ToString(...);
About formatting TimeSpan read here: http://msdn.microsoft.com/en-us/library/ee372286(v=vs.110).aspx
phmani469 19-May-14 5:38am    
within ToString(....) what value i want to give.....If i gave ToString("hh:mm tt") it throws an error

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