C++builder下的sqlserver2000事务处理

  //事务的处理
             try{
                ADOQuery1-> Close();
                ADOQuery1-> SQL-> Clear();
                //开始事务
                ADOQuery1-> SQL-> Add( "BEGIN   TRAN   ");
                //更新temp_price表的intime字段
                ADOQuery1->SQL->Add("update zzcz.dbo.temp_price set intime="+intimenow);
                //插入到sto_price表中
                ADOQuery1->SQL->Add("insert into zzcz.dbo.sto_price select * from zzcz.dbo.temp_price");
                //创建和cg30_p_p_price相似结构的表
                ADOQuery1->SQL->Add("create table zzcz.dbo.zz_price(start_date char(8) not null default '',stop_date char(8) not null default'',train_no char(12) not null,from_station_name char(10) not null default'郑州',to_station_name char(10) not null,ticket_type int not null default 0,belong_line tinyint not null default 0,seat_type_code char(1) not null default'',bed_level char(1) not null default'',price smallint not null,service_cost smallint not null default 0,origin char(2) not null default'',replicate_range int)");
                //插入zz_price表中相应的数据
                ADOQuery1->SQL->Add("insert into zzcz.dbo.zz_price(train_no,to_station_name,seat_type_code,bed_level,price) select train_no,station_name,substring(seat_type_code,1,1),substring(seat_type_code,2,1),convert(smallint,ticket_price) from zzcz.dbo.sto_price where intime="+intimenow);
                //删除cg30_p_price表中from_station_name为郑州的数据
                ADOQuery1->SQL->Add("delete from zzcz.dbo.cg30_p_p_price where from_station_name='郑州'");
                //把zz_price中的数据插入到cg30_p_p_price中去
                ADOQuery1->SQL->Add("insert into zzcz.dbo.cg30_p_p_price select * from zzcz.dbo.zz_price");
                //删除临时表temp_price
                ADOQuery1->SQL->Add("drop table zzcz.dbo.temp_price");
                //删除临时表zz_price
                ADOQuery1->SQL->Add("drop table zzcz.dbo.zz_price");
                //删除表sto_price中的旧数据
                ADOQuery1->SQL->Add("delete from zzcz.dbo.sto_price where datediff(ss,substring(intime,1,4)+'-'+substring(intime,5,2)+'-'+substring(intime,7,2)+' '+substring(intime,9,2)+':'+substring(intime,11,2)+':'+substring(intime,13,2),'"+datetime+"')>0");

                //提交事务
                ADOQuery1-> SQL-> Add( "COMMIT   TRAN   ");
                //如果出错回滚事务
                ADOQuery1-> SQL-> Add("IF  @@error   <>   0     ROLLBACK   TRAN");
                ADOQuery1-> ExecSQL();
             }catch(Exception &E)
             {
                ShowMessage(E.Message);
             }

 

//使用的ado组件。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值