简体   繁体   中英

Getting error “Input string was not in a correct format.” in SelectParameters

Query:

SELECT [VehicleId], [VehicleNumber], [VehicleBrand], [VehicleName], [ModelYear], [PurchasePrice]
FROM [VehicleMaster]
WHERE ([VehicleType]=@VehicleType or @VehicleType = '') and 
    ([VehicleNumber]=@VehicleNumber or @VehicleNumber is null) and 
    ([SaleStatus] = @SaleStatus or @SaleStatus = '-Select-') and 
    ([OwnershipStatus]=@OwnershipDetail or @OwnershipDetail = '-Select-')  and
    ([ModelYear] between @YearFrom and @YearTo or (@YearFrom = 'Year' and @YearTo = 'Year'))

Markup:

<SelectParameters>
    <asp:SessionParameter Name="VehicleType" SessionField="VehicleType" Type="String" />
    <asp:SessionParameter Name="VehicleNumber" SessionField="VehicleNumber" Type="String" />
    <asp:SessionParameter Name="SaleStatus" SessionField="SalesStatus" Type="String" />
    <asp:SessionParameter Name="OwnershipDetail" SessionField="OwnershipStatus" Type="String" />
    <asp:SessionParameter Name="YearFrom" SessionField="YearFrom" Type="Int32"  ConvertEmptyStringToNull="true" />
    <asp:SessionParameter Name="YearTo" SessionField="YearTo" Type="Int32" ConvertEmptyStringToNull="true" />
</SelectParameters>

Error:

Input string was not in a correct format.e....

(@YearFrom = 'Year' and @YearTo = 'Year')

would imply that the varaibles @YearFrom and @YearTo are strings, but you declare them as Int32

<asp:SessionParameter Name="YearFrom" SessionField="YearFrom" Type="Int32"  ConvertEmptyStringToNull="true" />
<asp:SessionParameter Name="YearTo" SessionField="YearTo" Type="Int32" ConvertEmptyStringToNull="true" />

Which will fail during execution since the string 'Year' isn't an int type.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM