我试图从数据库中提取一个整数,但是出现错误
我在控制器中的代码是:
Dim SeqNumQuery = From a In db.RequestedServices
Where a.RequestedServiceId = id
Select a.StationId
Dim StationId As Integer = SeqNumQuery.ToString
错误是:
范围变量'StationId'隐藏先前在查询表达式中定义的封闭块或范围变量中的变量。
答案 0 :(得分:3)
我认为问题在于您的变量StationId
正在某个范围内声明。尝试更改为:
Dim SeqNumQuery = From a In db.RequestedServices
Where a.RequestedServiceId = id
Select a.StationId
StationId = SeqNumQuery.ToString
但是看看正在使用的其他变量是什么。如果您需要,请使用StationId
以外的其他内容作为变量名称,例如RequestedServicesStationId
。
有关此错误的更多信息:
另外,我不明白为什么使用.ToString
扩展方法。这不会导致您的脚本抛出异常,但我建议将其更改为CInt()
:
StationId = CInt(SeqNumQuery)