Employers - Post Free Jobs
Forum guidelines
  • Home
  • »
  • WPF
  • »
  • How To Insert the value of Datetimepicker in SQL Database
AuthorQuestion
How To Insert the value of Datetimepicker in SQL Database
Posted on: 22 Apr 2013

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.


AuthorReply
Re: How To Insert the value of Datetimepicker in SQL Database
Posted on: 22 Apr 2013  
I think you should use SelectedDate property.

also look at this tutorial:

http://www.c-sharpcorner.com/UploadFile/mahesh/wpf-datepicker/

Re: How To Insert the value of Datetimepicker in SQL Database
Posted on: 23 Apr 2013  

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.


Employers - Post Free Jobs

SPONSORED BY

Offshore Software and Database Development
MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.