Click here to Skip to main content
13,141,576 members (53,208 online)
Rate this:
Please Sign up or sign in to vote.
See more:
i have to fields as follows

fromdate calendarimage

Todate calendarimage

which date i choose that date displayed both in the fromdate and todate.but in the database date stored in the format as 1/1/1900 12:00:00 AM.


fromdate and todate datatype is datetime in the database.

when i insert the date for this query as follows

SqlCommand cmd = new SqlCommand("insert into BirthDayWish values('" + txt_name.Text + "','" + FromDate.SelectedDateValue.ToString() + "','" + txt_mobile.Text + "','" + Todate.SelectedDateValue.ToString() + "','a','" + txt_Email.Text + "')", con);

please help me.
Posted 23-Dec-12 21:35pm
Vani Kulkarni 24-Dec-12 4:31am
Are fromdate and todate fields textboxes associated with calendar?

1 solution

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

Solution 1

The contents of FromDate.SelectedDateValue.ToString() and ToDate.SelectedDateValue.ToString() are not being recognised as valid dates or are null.

Debug and check their values.

Try putting some conditional statement around the sql to confirm you have valid data e.g. using DateTime.TryParse

Finally when using dates and databases it is always a good idea to be explicit and unambigous about date formats so try using FromDate.SelectedDateValue.ToString("dd-MMM-yyyy")

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 |
Web04 | 2.8.170915.1 | Last Updated 24 Dec 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