【发布时间】:2015-04-30 05:18:50
【问题描述】:
oComm = CreateCommand("IsMapAccessExist", spParams, TypeOfConnectionString.GeoAppBuilder);
bool exists = true;
exists = Boolean.Parse(oComm.ExecuteScalar().ToString());
return exist
exists 的值为 'true' 但它会引发错误
FormatException was caught
String was not recognized as a valid Boolean.
【问题讨论】:
-
你确定吗?
Boolean.Parse("true")工作正常。你的字符串也有这些单引号?您是否调试了代码并检查了ExecuteScalar的确切返回值? -
它被预先设置为真,但是是的,Boolean.Parse(oComm.ExecuteScalar().ToString()) 标记了该错误....并且我用 SQL 在数据库中检查了记录存在
-
oComm.ExecuteScalar().ToString()中返回了什么?当它试图将oComm.ExecuteScalar().ToString()中返回的内容转换为布尔值时,它会抛出异常。 -
您的问题在于 oComm.ExecuteScalar().ToString(),它没有返回 'true' 或 'false',因此会引发 FormatException。
-
730...不知道为什么 IsMapAccessExist 是一个返回记录的存储过程