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.
Jignesh TrivediPosted Apr 23, 2013, 12:01 AM
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.
Javeed M ShaikhPosted Apr 22, 2013, 4:49 PM
also look at this tutorial:
http://www.c-sharpcorner.com/UploadFile/mahesh/wpf-datepicker/