读书人

update与insert解决思路

发布时间: 2012-12-19 14:13:15 作者: rapoo

update与insert
for li_n =1 to m -1 step 1
ll_sn++
ls_tables = stu_parm.text[row]
ll_tables_no = stu_parm.sgno[row]
ll_date =CDT.DBToday()
ll_time =cdt.dbNow()
insert into ho_creditcard_handle
(text,sn,date,time,tables,tables_no,
userid,Log_ncard,Log_user,deleflag)
values(:ll_text,
:ll_sn,
:ll_date,
:ll_time,
:ls_tables,
:ll_tables_no,
:casher.uid,
:Card_no,
:casher.uid,
0)
using Hotel_db.trans();

if Hotel_db.trans().sqlcode < 0 then
Rollback Using Hotel_db.trans();
MessageBox('提示','数据保存失败!')
return
end if

//end if

commit using Hotel_db.trans();
row ++
next
大家帮看看上面的跟下面的代码多次保存效果能一样吗

for li_n =1 to m -1 step 1
ll_sn ++
free.object.tables[1] = stu_parm.text[row]
free.object.tables_no[1] = stu_parm.sgno[row]
free.object.deleflag[1] = 0
free.object.userid[1] = casher.uid
free.object.Log_ncard[1] = Card_no
free.object.Log_user[1] = casher.uid
free.object.sn[1] = ll_sn
free.object.date[1] = CDT.DBToday()
free.object.time[1] = cdt.dbNow()
free.update()
IF free.Update() <> 1 then
ROLLBACK USING Hotel_DB.Trans();
Messagebox( "","保存错误!" )
return
End if

COMMIT USING Hotel_DB.Trans();
//free.
//messagebox('',1)
row ++

next
[最优解释]

引用:
for li_n =1 to m -1 step 1
ll_sn++
ls_tables = stu_parm.text[row]
ll_tables_no = stu_parm.sgno[row]
ll_date =CDT.DBToday()
ll_time =cdt.dbNow()
insert into ho_creditcard_handle
……


大致看了一下,按你的逻辑2段代码没什么区别。
第二段你可以优化一下, 把 free.object.tables[1] 中的1换成循环的变量li_n,先把所有的数据都插入到DW中 ,最后一起update(),这样效率应该会高些。

[其他解释]
受教了 谢谢!不过你说完后我才知道 我写的下面一段代码只能插入一条而上面的就可以保存多条数据

读书人网 >PB

热点推荐