日期:2014-05-18 浏览次数:21026 次
string sqlshenhe = "INSERT INTO ClassLog ( DiQu,ZhuangTai,ShenheId,ShenheShiJian) (select DiQu,ZhuangTai,4,'2012-2-18 10:00:00' FROM ClassLogLuRu WHERE ClassLogLuRu_id =" + id + ") "; if (Convert.ToInt32(SqlHelper.ExecuteScalar(DBConn.ConnectionString, CommandType.Text, sqlshenhe)) > 0) { string sql = "delete from [ClassLogLuRu] where ClassLogLuRu_id =" + id; ................................... }
INSERT INTO ClassLog (DiQu, ZhuangTai, ShenheId, ShenheShiJian) (SELECT DiQu, ZhuangTai, 4, '2012-2-18 10:00:00' FROM ClassLogLuRu WHERE ClassLogLuRu_id = 701)
string sqlshenhe = @"INSERT INTO ClassLog ( DiQu,ZhuangTai,ShenheId,ShenheShiJian) select DiQu,ZhuangTai,4,'2012-2-18 10:00:00' FROM ClassLogLuRu WHERE ClassLogLuRu_id ="+id +"; //把你的代码改成这样试试
------解决方案--------------------
string sqlshenhe = @"INSERT INTO ClassLog ( DiQu,ZhuangTai,ShenheId,ShenheShiJian) select DiQu,ZhuangTai,4,'2012-2-18 10:00:00' FROM ClassLogLuRu WHERE ClassLogLuRu_id ="+id +";
改成这样试试:string sqlshenhe = string.Forma("INSERT INTO ClassLog ( DiQu,ZhuangTai,ShenheId,ShenheShiJian) select DiQu,ZhuangTai,4,{0} FROM ClassLogLuRu WHERE ClassLogLuRu_id ="+id +","2012-2-18 10:00:00");
我也出现过这种问题
最后请教了论坛里的人,发现原因居然是字符串错误:兴许是单引号和双引号的错误
------解决方案--------------------
ExecuteScalar 执行查询,并返回查询所返回的结果集中第一行的第一列。 忽略其他列或行
ExecuteNonQuery 对连接执行 Transact-SQL 语句并返回受影响的行数。