日期:2014-05-17  浏览次数:20674 次

叫号系统重号问题
因业务需要,派号时有多台机器在派号,因此自己测试,打开两台机器然后两只手各拿一个鼠标猛点派号,结果派出的号码有重复,求高手帮忙
实现派号的主要代码:

string sql = string.Format("select decode( max(p_num),null,0,max(p_num))+1 p_num from T_PAIHAO where P_DATA = '{2}' and to_char(createdtime,'yyyymmdd')=to_char(sysdate,'yyyymmdd') and P_QYID= '{0}' and P_YWLX= '{1}'", qyID, ywlxID, sj);
string maxNum = crjService.GetDataByTable(sql).Tables[0].Rows[0][0].ToString();
string sqlInsert = string.Format("insert into t_paihao (P_NUM,P_QYID,P_SFZ,P_YWLX,P_PHRQ,P_DNIP,P_DATA)values('{0}','{1}','{2}','{3}','{4}','{5}','{6}')",maxNum,qyID,sfzhm,ywlxID,timeNow,ipAdd,sj);
int result = crjService.ExecuteNonQuery(sqlInsert);

------解决方案--------------------
你就不能用自增列???
------解决方案--------------------
引用:
谢谢各位的回复,最后自己解决了。将两条SQL语句合成一条SQL语句执行,问题就解决了!

就是这么回事,合在一起的时候,Oracle会自动添加事务的,而Sqlserver则是可以使用外部变量在插入时记录插入值,都可以实现。