Home » Error » application error » Arithmetic overflow error converting expression to data type datetime

Arithmetic overflow error converting expression to data type datetime

Condition:

<asp:SqlDataSource ID="PolExpCurrentMo" runat="server" 
  ConnectionString="< %$ ConnectionStrings:appConnectionString2 %>" 
  SelectCommand="SELECT * FROM [VendorList] WHERE 
              _([EXPIRATION_DATE] >= @EXP_BEGIN) AND ([EXPIRATION_DATE] < @EXP_END) AND 
              _([EXPIRATION_CONTACT] = @EXPIRATION_CONTACT) ORDER BY EXPIRATION_DATE ">
  <selectparameters>
     <asp:parameter DefaultValue="YES" Name="EXPIRATION_CONTACT" Type="String" />
     <asp:parameter Name="EXP_BEGIN" Type="String"/>
     <asp:parameter Name="EXP_END" Type="String" />
  </selectparameters>

Code behind default value

' *current months date parameter 
PolExpCurrentMo.SelectParameters("EXP_BEGIN").DefaultValue = 
_DateTime.Now.Month.ToString() + "/1/" + DateTime.Now.Year.ToString() 'month begins

PolExpCurrentMo.SelectParameters("EXP_END").DefaultValue = 
_NxMonthValue + "/1/" + DateTime.Now.Year.ToString() 'month ends


Resolution

<asp:SqlDataSource ID="PolExpCurrentMo" runat="server" 
  ConnectionString="< %$ ConnectionStrings:appConnectionString2 %>" 
  SelectCommand="SELECT * FROM [VendorList] WHERE 
              _([EXPIRATION_DATE] >= @EXP_BEGIN) AND 
              _((convert(varchar,[EXPIRATION_DATE],111)) < @EXP_END) AND 
              _((convert,[EXPIRATION_CONTACT],111)) = @EXPIRATION_CONTACT) ORDER BY 
              _EXPIRATION_DATE ">
  <selectparameters>
     <asp:parameter DefaultValue="YES" Name="EXPIRATION_CONTACT" Type="String" />
     <asp:parameter Name="EXP_BEGIN" Type="String"/>
     <asp:parameter Name="EXP_END" Type="String" />
  </selectparameters>