2013-03-14 56 views
0

查詢:獲取錯誤「輸入字符串格式不正確。」在SelectParameters

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

標記:

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

錯誤:

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

+0

請向我們展示您的周邊代碼..目前這是一團糟。 – 2013-03-14 03:38:34

+0

「False」> Blockquote?這是什麼樣的情況? – 2013-03-14 03:39:42

+0

看起來你的服務器端代碼中存在錯誤的「blockquote」標籤......可能在HTML格式工具欄中出現錯誤的按鈕一次? – 2013-03-14 03:41:46

回答

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

將意味着varaibles @YearFrom@YearTo是字符串,但其聲明爲Int32

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

由於字符串'Year'不是int類型,因此在執行過程中會失敗。

+0

我也改變了它,但也出現了同樣的錯誤。 – 2013-03-14 03:54:10

+0

您是否將'年份'更改爲數字或將參數的類型更改爲「字符串」?這也可能意味着會話字段「Year From」具有非整數。錯誤消息表明某些字符串解析出錯了。很難說沒有完整的堆棧跟蹤的地方... – 2013-03-14 04:16:59