Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.

why?

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
Comments
Vani Kulkarni 24-Dec-12 4:31am    
Are fromdate and todate fields textboxes associated with calendar?

1 solution

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")
 
Share this answer
 

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


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900