c# SqlCommand 数据库里的int类型 删除的时候数据类型有问题

2025-12-06 00:05:47
推荐回答(5个)
回答1:

是sql数据库吗?即使cid 是int类型的, 也可以写成where cid=‘"+ Program.Selid +"' ,
可以在两边放上单引号 ,可以在查询分析器中测试一下,
还有你这个语句可以打一个断点调试的时候看一下最终的sql 语句是什么 ,然后去查询分析器中测试一下。

回答2:

可以删除的啊,是不是传入的参数不对,没有数据啊什么的
Program.Selid 不是int型吧,把它转成int型就可以了

回答3:

删除数据一般是用主键索引作为条件的,你怎么还搞了俩条件呢?你先查查,select * from custom where cid=Program.Selid and cname = 'Program.SelName'是什么结果~!

回答4:

string sql = "delete from custom where cid="+(int)Program.Selid +" and cname='"+ Program.Selname +"'";

回答5:

string sql = "delete from custom where cid="+Convert.ToInt32(Program.Selid )+" and cname='"+ Program.Selname +"'";