I am storing date as string in sql table. If date is not passed then it will be null. Now I want to check whether date is null from the design page of asp.net. I am getting error of type cast. Any one is having idea how to overcome this?
<%# ((DateTime)Eval("Date")).ToString("yyy-MM-dd hh:mm tt") %>">
Here data is getting as string input.
Thanks
I am storing date as string in SQL table.
This is your first problem (here is a good explanation of why this is a problem).
I am getting error of type cast.
This is how your first problem (storing a date as a string) causes your second problem (type cast error). Although it is possible to fix this by parsing the date from a string using DateTime.Parse, DateTime.ParseExact, or DateTime.TryParse, I would strongly recommend against using any of these approaches.
The good news is that once you fix the first problem, the second problem goes away by itself!
Use this approach to change the type of the column without losing the data:
date to your tabledate column from the old varchar column that contains string representations of datesvarchar columnIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With