Click here to Skip to main content
15,884,794 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi!

I want to know how to we can get a date value in text box and after converting string to date type store in database in date type.where DateTime.parse(textbox1.text)/DateTime.ParseExact(TextBox1.Text,"DD/MM/YYYYY:HH:MM:SS",null)does not working properly?
Posted
Comments
[no name] 28-Aug-12 11:55am    
Why is it that you think that DateTime.Parse "does not work properly"? It does work if you use it correctly. Use a DateTimePicker and you would not have to worry about converting.
ZurdoDev 28-Aug-12 11:55am    
You can store any text that looks like a date in a SQL database date field so I am not sure what problem you are having.
Christian Graus 28-Aug-12 12:04pm    
Storing dates as text is pure idiocy. He wants to store them as dates and is having trouble parsing them in to dates.
ZurdoDev 28-Aug-12 12:20pm    
That isn't what I was saying. You can take anything from a textbox that looks like a date and store it in SQL as a date.
Christian Graus 30-Aug-12 12:07pm    
So long as you first make sure it is a date, I agree.

1 solution

They don't work because your text is not valid. Use DateTime.TryParse. You can specific, for example, the US format if you're in India and writing for the US. Then, if it fails, your string is not a valid date.

Of course you could use a date picker control, then your data will be a date to start with.
 
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