W
weiyuan99
Unregistered / Unconfirmed
GUEST, unregistred user!
1. 发现有时动态创建TADOStoredProc,调用执行过程一切正常,
可是没有执行结果,也得不到返回值,有时可以,不稳定,我的代码如下:
//-----------------------------------------------------------
//取服务器时间
TDateTime __fastcall TBillControl::GetToday()
{
TADOStoredProc *ADOStoredProc;
TParameter * Parameter ;
TDateTime dtRetVal;
try
{
dtRetVal =NULL;
ADOStoredProc = new TADOStoredProc(NULL);
ADOStoredProc->ProcedureName ="UP_GETSERVERSYSDATE";
Parameter= new TParameter(ADOStoredProc->Parameters);
Parameter->DataType = ftDateTime;
Parameter->Name = "@dtSySDateTime";
Parameter->Direction = pdInputOutput;
ADOStoredProc->Connection = FConnection;
ADOStoredProc->ExecProc();
dtRetVal = StrToDateTime(ADOStoredProc->Parameters ->ParamValues["@dtSySDateTime"]);
if(Parameter!=NULL){delete Parameter;Parameter=NULL;}
if(ADOStoredProc!=NULL){delete ADOStoredProc;ADOStoredProc=NULL;}
FDateTime = dtRetVal;
return dtRetVal;
}
catch(...)
{
if(Parameter!=NULL){delete Parameter;Parameter=NULL;}
if(ADOStoredProc!=NULL){delete ADOStoredProc;ADOStoredProc=NULL;}
return dtRetVal;
}
}
2. SQLServer2000的事务控制
.....
begin
begin trans
delete from cs_tbl_moduleInfo
insert into cs_tbl_moduleInfo(mod_sMid,mod_sMname,mod_sid,mod_sName,tr_date,tr_state)
values('1','文件','101','数据备份与恢复','','')
insert into cs_tbl_moduleInfo(mod_sMid,mod_sMname,mod_sid,mod_sName,tr_date,tr_state)
values('1','文件','102','数据处理与传输','','')
insert into cs_tbl_moduleInfo(mod_sMid,mod_sMname,mod_sid,mod_sName,tr_date,tr_state)
values('1','文件','103','部门信息','','')
commit trans
if(@@error <> 0)
rollback trans
.....
假如,第三条记录已经存在,无法插入,本应滚回事务,但是,前两行还是可以插入,为什么???
可是没有执行结果,也得不到返回值,有时可以,不稳定,我的代码如下:
//-----------------------------------------------------------
//取服务器时间
TDateTime __fastcall TBillControl::GetToday()
{
TADOStoredProc *ADOStoredProc;
TParameter * Parameter ;
TDateTime dtRetVal;
try
{
dtRetVal =NULL;
ADOStoredProc = new TADOStoredProc(NULL);
ADOStoredProc->ProcedureName ="UP_GETSERVERSYSDATE";
Parameter= new TParameter(ADOStoredProc->Parameters);
Parameter->DataType = ftDateTime;
Parameter->Name = "@dtSySDateTime";
Parameter->Direction = pdInputOutput;
ADOStoredProc->Connection = FConnection;
ADOStoredProc->ExecProc();
dtRetVal = StrToDateTime(ADOStoredProc->Parameters ->ParamValues["@dtSySDateTime"]);
if(Parameter!=NULL){delete Parameter;Parameter=NULL;}
if(ADOStoredProc!=NULL){delete ADOStoredProc;ADOStoredProc=NULL;}
FDateTime = dtRetVal;
return dtRetVal;
}
catch(...)
{
if(Parameter!=NULL){delete Parameter;Parameter=NULL;}
if(ADOStoredProc!=NULL){delete ADOStoredProc;ADOStoredProc=NULL;}
return dtRetVal;
}
}
2. SQLServer2000的事务控制
.....
begin
begin trans
delete from cs_tbl_moduleInfo
insert into cs_tbl_moduleInfo(mod_sMid,mod_sMname,mod_sid,mod_sName,tr_date,tr_state)
values('1','文件','101','数据备份与恢复','','')
insert into cs_tbl_moduleInfo(mod_sMid,mod_sMname,mod_sid,mod_sName,tr_date,tr_state)
values('1','文件','102','数据处理与传输','','')
insert into cs_tbl_moduleInfo(mod_sMid,mod_sMname,mod_sid,mod_sName,tr_date,tr_state)
values('1','文件','103','部门信息','','')
commit trans
if(@@error <> 0)
rollback trans
.....
假如,第三条记录已经存在,无法插入,本应滚回事务,但是,前两行还是可以插入,为什么???