注册 登录
编程论坛 PowerBuilder

在線等幫助謝謝

ailmheqin 发布于 2007-07-17 12:15, 1445 次点击
Date l_rq
dw_2.AcceptText()
String l_card,l_money,l_row
l_rq = dw_2.GetItemDate(1,'rq')
l_card = dw_2.GetItemString(1,'bankcardno')
l_money = dw_2.GetItemString(1,'money')
SELECT bankcardno INTO :l_row FROM vip_active1 WHERE bankcardno = :l_card ;
IF SQLCA.SQLCODE=0 THEN
MessageBox('提示','該卡號存在')
Return
ELSE
INSERT INTO vip_active1 VALUES(:l_card,:l_money,to_date(:l_rq));
COMMIT;
MessageBox('提示','保存成功')
END IF

這個語句不判斷重復的卡號~~我用相同的卡號進行保存還是可以保存成功
4 回复
#2
sam20802007-07-17 13:14
可以这样改改
法一:
Date l_rq
dw_2.AcceptText()
String l_card,l_money --,l_row
Long ll_count = 0
--如果数据窗可能 有多条数据的话,必须进行循环判断
l_rq = dw_2.GetItemDate(1,'rq')
l_card = dw_2.GetItemString(1,'bankcardno')
l_money = dw_2.GetItemString(1,'money')
--SELECT bankcardno INTO :l_row FROM vip_active1 WHERE bankcardno = :l_card ;
Select count(*) Into :ll_count From vip_active1 Where bankcardno = :l_card;
--IF SQLCA.SQLCODE=0 THEN
If ll_count > 0 Then
MessageBox('提示','該卡號存在')
Return
ELSE
INSERT INTO vip_active1 VALUES(:l_card,:l_money,to_date(:l_rq));
COMMIT;
MessageBox('提示','保存成功')
END IF

法二:
修改下数据结构,把bankcardno改为不可重复的字段
#3
千金散尽2007-07-17 14:18

Select count(*) Into :ll_count From vip_active1 Where bankcardno = :l_card;
--IF SQLCA.SQLCODE=0 THEN
If ll_count > 0 Then
update vip_active1
set l_money = '总和'
where bankcardno = :l_card;
ELSE
INSERT INTO vip_active1 VALUES(:l_card,:l_money,to_date(:l_rq));
COMMIT;
MessageBox('提示','保存成功')
END IF

#4
ailmheqin2007-07-17 16:24

ok了謝謝啊~

#5
ugly9278462007-07-17 20:19
厉害
1