Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
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 23-Dec-12 21:35pm
Comments
Vani Kulkarni at 24-Dec-12 4:31am
   
Are fromdate and todate fields textboxes associated with calendar?

1 solution

Rate this: bad
good
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")
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web03 | 2.8.141022.1 | Last Updated 24 Dec 2012
Copyright © CodeProject, 1999-2014
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