Hello, I'm having a problem with inserting date from datetimepicker into sql. The thing is - I don't know how to do it.
I'm using WPF with LINQ to sql database connection.
This is how it should work :
In the button Insert I want to put name, surname and date of birth into sql database.
So I have
Person p=new Person();
p.Name=nameTextBox.Text.Trim();
p.surName=surNameTextBox.Text.Trim();
p.dateOfBirth= // I don't know how
Thanks in advance.

Javeed M ShaikhRank #839 · 2.7K reputationPosted Apr 22, 2013, 12:49 PM EDT
also look at this tutorial:
http://www.c-sharpcorner.com/UploadFile/mahesh/wpf-datepicker/
Jignesh TrivediRank #16 · 50.3K reputationPosted Apr 22, 2013, 8:01 PM EDT
hi,
In this case you can use DateTime.TryParse and DateTime.TryParseExact to cast your date from date picker.
string dateString = "Mon 22 Apr 8:30 AM 2013"; // date from your datepicker
string format = "ddd dd MMM h:mm tt yyyy"; // specify your date format with set in datetime picker
DateTime dateTime;
DateTime.TryParseExact(dateString, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime);
p.dateOfBirth= dateTime;
hope this will help you.