I’m trying to insert selected date from calender in asp.net to Microsoft SQL database.
When I select time like 01/04/2012 its work, but when trying to insert 30/01/2012 I’m getting the message:
The conversion of a char data type to a datetime data type resulted in
an out-of-range datetime value.
When I create the datetime object by using closeDateCalender.SelectedDate,
the code in c# is :
sb.AppendFormat("Values('{0}', '{1}' ,'{2}', '{3}','{4}','{5}','{6}','{7}')",
opportunity.UserId,
opportunity.AccountId,
opportunity.OpportunityName,
opportunity.CloseDate,
opportunity.Stage,
opportunity.Probability,
opportunity.Amount,
opportunity.Description);
String prefix = "INSERT INTO Opportunities " + "([User_Id],Account_Id,Opportunity_Name,Close_Date,Stage,Probabilty,Amount,[Description])";
command = prefix + sb.ToString();
any idea how to solve it???
Your server is set to accept dates in American format rather than European. If you reformat the date so that it’s in the format
yyyy-MM-ddit will work.Try this: