下面是本人学数据库时作的笔记:应该还算挺具体的,其实主要就是几个参数,而SQL语句都是一样的。使用Connection对象的Execute_RecordsetPtr connection15::Execute(_bstr_t CommandText,VARIANT* RecordsAffected, long Options) CommandText 命令文本 RecordsAffected 操作完成后所影响的行数 Options 命令文本的类型取值和Recordset类的Open函数中的Options一样。_variant_t aff;theApp.m_pConn->Execute(_T("insert into name(姓名,性别,年龄)alues('zhong',false,21)"),
&aff,adCmdText);record1=m_pConn->Execute(_T("select count(*) from name"),&aff,adCmdText);使用Command对象的Execute_CommandPtr m_pComm;m_pComm.CreateInstance(__uuidof(Command));m_pComm->ActiveConnection=theApp.m_pConn;m_pComm->CommandText=_T("insert into name(姓名,性别,年龄) values('chang',false,22)");m_pComm->Execute(NULL,NULL,adCmdText);strSql.Format("select distinct num from bank1 where bank='%s'",entry->name);strSql=_T("select distinct bank from bank1");strSql.Format("select sum(amount) from bank1 where num='%s'",str1);注意:不管是哪个对象执行SQL命令返回的Recordset都是只读的,不能对数据进行修改。如要修改只能使用Recordset类自己的Open函数。 |