【问题标题】:Getting error "Input string was not in a correct format." in SelectParameters收到错误“输入字符串的格式不正确。”在选择参数中
【发布时间】:2013-03-14 03:36:25
【问题描述】:

查询:

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

标记:

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

错误:

输入字符串的格式不正确。e....

【问题讨论】:

  • 请向我们展示您周围的代码.. 目前这是一团糟。
  • "False">块引用?这是什么状态?
  • 您的服务器端代码中似乎有放错位置的“blockquote”标签...可能在 HTML 格式工具栏中点击了错误的按钮一次?
  • 您声明 @YearFrom@YearTo 为 Int32,但将它们与“年份”进行比较 - 这不是一个数字。 - 至少我在已编辑的已发布查询中看了一眼:)
  • 哇..,问题中的查询发生了什么?现在它的参数??

标签: c# asp.net sql-server tsql ado.net


【解决方案1】:
(@YearFrom = 'Year' and @YearTo = 'Year')

意味着变量 @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 类型。

【讨论】:

  • 您是否将“年份”更改为数字或参数类型更改为“字符串”?这也可能意味着会话字段“Year From”具有非整数。错误消息表明某些字符串解析出错。如果没有完整的堆栈跟踪,很难说出位置......
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多