删除表中重复的记录,只保留一条
delete from tablename
where id not in
(select max(id)
from tablename
group by 重复字段名)
where id not in
(select max(id)
from tablename
group by 重复字段名)
应该还有其他方法, 希望知道的人可以留下你的写法。
http://blog.csdn.net/ocan/archive/2006/10/10/1329326.aspx数据库字段ID是bigint型,在执行某个存储过程后,其中存储过程SQL是这样的:select ID,…………
在程序中声明了变量是int型,在执行存储过程后,以下情况是会抛出异常的:
1、obj.ID = dr.IsDBNull(0) ? 0 : dr.GetInt32(0);
2、obj.ID = (dr["ID"]==null)?0:(int)dr["ID"];
3、obj.ID = (dr["ID"]==null)?0:(Int32)dr["ID"];
解决办法:
把变量声明为Int64
1、obj.ID = dr.IsDBNull(0) ? 0 : dr.GetInt64(0);
2、obj.ID = (dr["ID"]==null)?0:(Int64)dr["ID"];
或用Convert.ToInt32()、int.Parse()强制转换。
以上方法已经验证,不知道还有没有更好的其他办法?有的话请补上。。。
http://blog.csdn.net/ocan/archive/2006/10/10/1329373.aspx
http://blog.csdn.net/ocan/archive/2006/10/10/1329373.aspx
BNull与string.empty
二者大大地不同。
DBNull空值;string.empty输入一个空字符串!
浙公网安备 33010602011771号