
常用软件类: |
|杀毒安全 | |联络聊天 | |网络软件 | |多媒体类 | |系统工具 | |图形图像 | |系统工具 | |应用软件 | |行业软件 |
开发设计类: |
|动画制作 | |图像处理 | |3D设计 | |操作系统 | |站长学院 | |网络相关 | |WEB设计 | |数据库类 | |程序开发 |
| _variant_t var; CString strName,strAge; try { if(!m_pRecordset->BOF) m_pRecordset->MoveFirst(); else { AfxMessageBox("表内数据为空"); return; } // 读入库中各字段并加入列表框中 while(!m_pRecordset->adoEOF) { var = m_pRecordset->GetCollect("Name"); if(var.vt != VT_NULL) strName = (LPCSTR)_bstr_t(var); var = m_pRecordset->GetCollect("Age"); if(var.vt != VT_NULL) strAge = (LPCSTR)_bstr_t(var); m_AccessList.AddString( strName + " --> "+strAge ); m_pRecordset->MoveNext(); } // 默认列表指向第一项,同时移动记录指针并显示 m_AccessList.SetCurSel(0); } catch(_com_error *e) { AfxMessageBox(e->ErrorMessage()); } |
| try { // 写入各字段值 m_pRecordset->AddNew(); m_pRecordset->PutCollect("Name", _variant_t(m_Name)); m_pRecordset->PutCollect("Age", atol(m_Age)); m_pRecordset->Update(); AfxMessageBox("插入成功!"); } catch(_com_error *e) { AfxMessageBox(e->ErrorMessage()); } |
| try { int curSel = m_AccessList.GetCurSel(); // 先将指针移向第一条记录,然后就可以相对第一条记录来随意移动记录指针 m_pRecordset->MoveFirst(); m_pRecordset->Move(long(curSel)); } catch(_com_error *e) { AfxMessageBox(e->ErrorMessage()); } |
| try { // 假设对第二条记录进行修改 m_pRecordset->MoveFirst(); m_pRecordset->Move(1); // 从0开始 m_pRecordset->PutCollect("Name", _variant_t(m_Name)); m_pRecordset->PutCollect("Age", atol(m_Age)); m_pRecordset->Update(); } catch(_com_error *e) { AfxMessageBox(e->ErrorMessage()); } |
| try { // 假设删除第二条记录 m_pRecordset->MoveFirst(); m_pRecordset->Move(1); // 从0开始 m_pRecordset->Delete(adAffectCurrent); // 参数adAffectCurrent为删除当前记录 m_pRecordset->Update(); } catch(_com_error *e) { AfxMessageBox(e->ErrorMessage()); } |
| m_pRecordset->Close(); m_pRecordset = NULL; |
| _CommandPtr m_pCommand; m_pCommand.CreateInstance(__uuidof(Command)); m_pCommand->ActiveConnection = m_pConnection; // 将库连接赋于它 m_pCommand->CommandText = "SELECT * FROM DemoTable"; // SQL语句 m_pRecordset = m_pCommand->Execute(NULL, NULL,adCmdText); // 执行SQL语句,返回记录集 |
| _CommandPtr m_pCommand; m_pCommand.CreateInstance(__uuidof(Command)); m_pCommand->ActiveConnection = m_pConnection; // 将库连接赋于它 m_pCommand->CommandText = "Demo"; m_pCommand->Execute(NULL,NULL, adCmdStoredProc); |