I have a date in a DataTable (dt). How to read a Date from a DataTable into a textbox
I can read a string in fine:
tbEvent.Text = dt.Rows[0].Field<String>(0);
I tried this but I get an error:
Unable to cast object of type ‘System.DateTime’ to type
‘System.String’.
tbDate.Text = dt.Rows[0].Field<DateTime>(1);
Regards
Tea
try
Textbox.Textonly accepts string values – so you need to convert.Updated
To format the string to show specific values you can use the custom format strings – http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx
so the above becomes
for db date
12/23/2012 12:25:45it will produce23/12/2012.