【发布时间】:2011-06-15 22:41:03
【问题描述】:
只要我有
Dim catID as integer
我在这样的查询中使用它:
cmd.CommandText = "select * from categories where parentid='" + catID + "'"
我明白了:
从字符串
select * from categories where p到类型Double的转换无效。
为什么会这样?
sql 中的parentid 数据类型为integer。
【问题讨论】:
-
试试这个:cmd.CommandText = "select * from categories where parentid='" + catID.ToString() + "'" 另外,只是一个想法:你正在为 parentid 指定 catid...如果在 SQL Server Management Studio 中,您的上述查询会运行吗?
-
请始终使用参数化查询,切勿串联字符串。
-
这个错误信息是从哪里来的?我怀疑它是 SQL Server,因为 Double 数据类型称为 Float。
标签: sql vb.net visual-studio-2010