Saranya Loganathan
Saranya Loganathan

Reputation: 49

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....

Upvotes: 0

Views: 2190

Answers (1)

Roman Gruber
Roman Gruber

Reputation: 1391

(@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.

Upvotes: 1

Related Questions