Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#3.5
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 28-Aug-12 5:49am
Escortx420
Comments
Wes Aday at 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 at 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 at 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 at 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 at 30-Aug-12 12:07pm
   
So long as you first make sure it is a date, I agree.

1 solution

Rate this: bad
good
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.
  Permalink  
v2

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



Advertise | Privacy | Mobile
Web02 | 2.8.141015.1 | Last Updated 28 Aug 2012
Copyright © CodeProject, 1999-2014
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