Click here to Skip to main content
13,196,126 members (49,926 online)
Rate this:
Please Sign up or sign in to vote.
See more:

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 28-Aug-12 5:49am
Wes Aday 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.
ryanb31 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.
ryanb31 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

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.171019.1 | Last Updated 28 Aug 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100