Guna

Guna

  • NA
  • 17
  • 0

string was not recognized as a valid datetime in c#

Jan 13 2016 4:45 AM

Friends,

Please find my code as follows;

  1. objsptfsnotegen.sptfqryargs = "select CONVERT(varchar(10),DATEPART(MM,MAX(iinfill_completion)))+'/'+CONVERT(varchar(10),DATEPART(DD,MAX(iinfill_completion)))+'/'+CONVERT(varchar(10),DATEPART(YYYY,MAX(iinfill_completion))) completionyear from bg_sptfinfillingreports repa join bg_sptfAppliedArea apa on apa.pKey_applied_area_id=repa.pKey_applied_area_id where tran_id=" + hiddentranid.Value;  
  2.           
  3.             String m_completiondate = objsptfsnotegen.GetCustomeData();  
  4.             if (m_completiondate != "")  
  5.             {  
  6.                 if (!string.IsNullOrEmpty(m_completiondate))  
  7.                 {  
  8.                     DateTime dt1 = DateTime.Parse(m_completiondate);  
  9.                     DateTime dt2 = DateTime.ParseExact("12/10/2014""MM/dd/yyyy", CultureInfo.InvariantCulture);  
  10.                     DateTime date1 = new DateTime(dt1.Year, dt1.Month, dt1.Day);  
  11.                     DateTime date2 = new DateTime(dt2.Year, dt2.Month, dt2.Day);  
  12.   
  13.                     int result = DateTime.Compare(date1, date2);  
  14.   
  15.                     if (result < 0)  
  16.                         objsptfsnotegen.sptfqryargs = "select top 1 CONVERT(varchar(50),Year_Announce) years,Scheme_Amount from scheme_anoncement sa join scheme_master sm on sm.Scheme_ID=sa.Scheme_ID where Scheme_Type_ID=1 and Scheme_Name='" + m_activityname + "_BG' and Year_Announce<='" + m_completiondate + "' and scheme_region='" + hiddenregion.Value + "' order by years desc";  
  17.                     else if (result == 0)  
  18.                         objsptfsnotegen.sptfqryargs = "select top 1 CONVERT(varchar(50),Year_Announce) years,Scheme_Amount from scheme_anoncement sa join scheme_master sm on sm.Scheme_ID=sa.Scheme_ID where Scheme_Type_ID=9 and Scheme_Name='" + m_activityname + "_BG' and Year_Announce<='" + m_completiondate + "' and scheme_region='" + hiddenregion.Value + "' order by years desc";  
  19.                     else  
  20.                         objsptfsnotegen.sptfqryargs = "select top 1 CONVERT(varchar(50),Year_Announce) years,Scheme_Amount from scheme_anoncement sa join scheme_master sm on sm.Scheme_ID=sa.Scheme_ID where Scheme_Type_ID=9 and Scheme_Name='" + m_activityname + "_BG' and Year_Announce<='" + m_completiondate + "' and scheme_region='" + hiddenregion.Value + "' order by years desc";  
  21.                 }   
 

The error is coming where i bold in code... Err. Name string was not recognized as a valid datetime in c#...

I had tried many ways but i can't. Please help me to fix this issue.

Thanks & Regards,


Answers (11)