2013-03-14 102 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