Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am using ajax calender extender

here is my html code

XML
<cc1:CalendarExtender ID="txt_student_birthdate_CalendarExtender"
                              runat="server" Enabled="True" Format="dd/MM/yyyy"
                              TargetControlID="txt_student_birthdate">
                          </cc1:CalendarExtender>



here is code

a.filldata("insert into student_registration_table values('" + txt_student_id.Text + "','" + txt_student_firstname.Text + "' , '" + txt_student_middlename.Text + "' , '" + txt_student_lastname.Text + "', '" + txt_student_address.Text + "' , '" + txt_student_city.Text + "', '" + txt_student_gender.SelectedValue + "' , '" + txt_student_emailid.Text + "' , '" + txt_student_landline.Text + "' , '" + txt_student_mobileno.Text + "' , '" + Convert.ToDateTime(txt_student_registrationdate.Text)+ "' , '" + Convert.ToDateTime(txt_student_birthdate.Text)+ "' , '" + txt_student_batch.SelectedValue + "' , '" + student_photo_path + "' , '" + txt_student_isactive.SelectedValue + "' ) ");

when i am entring date between 2009-2010 it will work perfactly.
but when i am entering date between 1980-90 it will show following error.

The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
The statement has been terminated.
Posted

This was of inserting a record in the DB is totally unacceptable! Don't know if someone does a code-review or not to tell how badly it is written.

What you are facing is not related to Calendar control, it's about the way it's being assigned in order to insert it into SQL.

Streamline your code, pass on the values to the query as parameters. Everything will work fine.
 
Share this answer
 
hi...

I am telling you a simple trick by which you can solve your problem.
instead of sending date in Date format in database send it into database as Convert.toString("txt_student_birthdate.Text")... it will be save as in Date time Format(mm/dd/yyyy) automatically in database but remain that in database attribute type should be DateTime.


Thanks
 
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