zoukankan      html  css  js  c++  java
  • 用Execute操作数据库

    1、原型是:_ConnectionPtr Execute( _bstr_t CommandText, VARIANT * RecordsAffected,


    long Options );

     参数
      1. CommandText是命令字符串,通常是SQL命令,也可以是表名、存储过程等
      2. RecordsAffected 可选,是操作完成后所影响的行数
      3. Options 可选,解释CommandText参数的方式,Options可以是CommandTypeEnum或ExecuteOptionEnum枚举用Execute操作数据库(转载)类型值
      
      类型
      说明
      adCmdUnspecifed=-1
      未描述CommandType属性
      adCmdText=1
      指示提供者应将 CommandText 赋值为命令的文本定义。
      adCmdTableDirect
      指示提供者应从 CommandText 命名的表中返回所有行。
      adCmdTable=2
      指示提供者应将 CommandText 赋值为表名。
      adCmdStoredProc=4
      指示提供者应将 CommandText 赋值为存储过程。
      adCmdUnknown=8
      指示 CommandText 参数中的命令类型未知。
      adExecuteAsync
      指示命令应该异步执行。
      adFetchAsync
      指示 CacheSize 属性指定的初始数量之后的行应异步提取。
      

    2、应用:
    先定义一个变量variant_t RecordsAffected;
    String str;
    添加记录:
    // str.Format("delete from stuInfo where stuID=60213");
    str.Format("insert into stuInfo values('孟子',80203,'男',23,'化学院','湖北',68,'06教本1班')");
    // m_pConnection->Execute((_bstr_t)str,NULL,adCmdText);
    m_pConnection->Execute((_bstr_t)str,&RecordsAffected,adCmdText);
    通过对话框添加记录 :
    variant_t RecordsAffected;
    strExec.Format("insert into stuInfo values('%s',%ld,'%s',%d,'%s','%s',%d,'%s')",dlg.m_stuName,(atol)(dlg.m_stuID),dlg.m_sex,
    (atoi)(dlg.m_age),dlg.m_dept,dlg.m_nativePlace,(atoi)(dlg.m_score),dlg.m_class);
    删除记录:
    strExec.Format("delete from stuInfo where stuID=%ld",(atol)(m_ListCtrl.GetItemText(iItem,0)));
    修改记录:
    strExec.Format("update stuInfo set stuName='%s' where stuID=%d",dlg.m_stuName,(atol)(dlg.m_stuID));
    m_pConnection->Execute((_bstr_t)strExec,&RecordsAffected,adCmdText);

  • 相关阅读:
    [GEiv]第七章:着色器 高效GPU渲染方案
    Cocos2d-x 脚本语言Lua介绍
    TestNg依靠先进的采用强制的依赖,并依赖序列的------TestNg依赖于特定的解释(两)
    uboot通过使用U磁盘引导内核RT5350成功
    linux下一个rsync工具和配置
    STM32 模拟I2C (STM32F051)
    Something write in FSE 2014
    ESB (Enterprise Service Bus) 入门
    Spring框架:Spring安全
    “TNS-03505:无法解析名称”问题解决一例
  • 原文地址:https://www.cnblogs.com/zhaoxinshanwei/p/3848663.html
Copyright © 2011-2022 走看看