ADOExecute使用

博客转移:http://vivianke.blog.163.com/blog/static/29715271200781121321529/

 

说明:ADOExecute(_variant_t &sql)函数处理,无记录集返回的数据库操作,这部分需要事务处理,
ADOExecute(_RecordsetPtr &ADOSet, _variant_t &sql)处理无记录集返回的数据库操作,这部分不需要事务处理,
在ADOConn->BeginTrans()和ADOConn->CommitTrans()之间,只能建立一个_RecordsetPtr记录集对象

if (m_bAppend) {        //添加入库
    //开始事务
    theApp.ADOConn->BeginTrans();    
    //形成入库编号
    strNO=Time.Format("%Y%m%d%H%M%S");
    sql="insert msave values('"
        +strNO+"','"
        +m_strID+"','"
        +m_strName+"','"
        +m_strSpec+"','"
        +m_strKind+"','"
        +m_strUnit+"',"
        +m_strAccount+","
        +m_strPrice+","
        +m_strValue+",'"
        +m_strDate+"','"
        +m_strDeal_person+"','"
        +m_strSave_person+"','"
        +m_strBase+"','"
        +m_strMemo+"')";
    theApp.ADOExecute(sql);
    //判断该物资是否有库存记录
    sql="select * from msurplus where yeid='"
        +m_strID
        +"' and yebase='"
        +m_strBase+"'";
    theApp.ADOExecute(theApp.m_pADOSet,sql);
    int iCount=theApp.m_pADOSet->GetRecordCount();
    if (iCount!=0){ //修改库存表
        _variant_t Holder;
        CString strAccount;
        int iSurplus,iSave;
        Holder=theApp.m_pADOSet->GetCollect("yeaccount");
        iSurplus=(int)Holder.dblVal;
        sscanf(m_strAccount,"%d",&iSave);
        iSurplus+=iSave;
        strAccount.Format("%d",iSurplus);
        //修改余额表
        sql="update msurplus set yeaccount="
            +strAccount+" where yeid='"
            +m_strID
            +"' and yebase='"
            +m_strBase+"'";
        theApp.ADOExecute(sql);
    }
    else{
        //若没有库存记录,则添加新的记录
        sql="insert msurplus values('"
            +m_strID+"','"
            +m_strName+"','"
            +m_strSpec+"','"
            +m_strKind+"','"
            +m_strUnit+"',"
            +m_strAccount+","
            +m_strValue+",'"
            +m_strBase+"','"
            +m_strMemo+"')";
        theApp.ADOExecute(sql);
    }
    //提交事务
    theApp.ADOConn->CommitTrans();    
}

BOOL CMaterial_MISApp::ADOExecute(_variant_t &sql)
{
    try{
        ADOConn->Execute((_bstr_t)sql,NULL,adCmdUnknown);
        return true;
    }
    catch (_com_error e) {
        CString strErr;
        strErr.Format("%s",(char*)e.Description());
        AfxMessageBox(strErr);
        return false;
    }
}

BOOL CMaterial_MISApp::ADOExecute(_RecordsetPtr &ADOSet, _variant_t &sql)
{    
    //to check state of recordset
    if (ADOSet->GetState() ==adStateOpen) {
        ADOSet->Close();        //close recordset
    }    
    try
    {
        ADOSet->Open(sql,ADOConn.GetInterfacePtr(),adOpenKeyset,adLockOptimistic,adCmdUnknown);
        return true;
    }
    catch (_com_error e) {
        CString strErr;
        strErr.Format("%s",(char*)e.Description());
        AfxMessageBox(strErr,MB_ICONEXCLAMATION);
        return false;
    }
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值