Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有问题的代码:
NpgsqlCommand if_ex = new NpgsqlCommand("SELECT count(id_unit) FROM unit WHERE name=" + "'" + tmp + "'", conn); int ex = (int)if_ex.ExecuteScalar();
抛出异常:
指定的演员表无效。
我正在尝试获取具有相同名称的列的行数(我传递的字符串)
我知道我应该使用参数,但此时我只测试了一些东西,所以我想现在还不如这样做。
发生此问题是因为查询的返回类型如:select count(*) 是 long 而不是 int。如果您将代码更改为 long ex = (long)if_ex.ExecuteScalar(); 你会得到你想要的。我希望它有所帮助。