VC++ update数据库的方法

void Preprocess::SplitDocument(int begin,int end,string tablename)
{
 char * selectbySpecificId=new char [1000];
 memset(selectbySpecificId,0,1000);
 sprintf_s(selectbySpecificId,1000,"select ArticleId,CAbstract1 ,CAbstract from %s where ArticleId between %d and %d",tablename.c_str(),begin,end);
 if(!ICTCLAS_Init())
 {
  printf("ICTCLAS INIT FAILED!\n");
  string strerr("there is a error");

 }
 ICTCLAS_SetPOSmap(ICT_POS_MAP_SECOND);
 CoInitialize(NULL);
 _ConnectionPtr pConn(__uuidof(Connection));
 _RecordsetPtr pRst(__uuidof(Recordset));
 pConn->ConnectionString="Provider=SQLOLEDB.1;Password=ssssss;Persist Security Info=True; User ID=sa;Initial Catalog=FinallyCorpus";
 pConn->Open("","","",adConnectUnspecified);
 pRst.CreateInstance("ADODB.Recordset");
 pRst->Open(selectbySpecificId,
  _variant_t((IDispatch*)pConn,true),
  adOpenStatic,
  adLockOptimistic,
  adCmdText);

 //pRst=pConn->Execute(,NULL,adCmdText);

 while (!pRst->rsEOF)
 {
  
  string rawtext=(_bstr_t)pRst->GetCollect("CAbstract1");
  //rawtext=ProcessforMSSQL(rawtext);
  string tempid=(_bstr_t)pRst->GetCollect("ArticleId");
  const char* sInput=rawtext.c_str();
  string sResult=ICTsplit(sInput);
  _variant_t vColumn,vValue;
  vColumn.SetString("CAbstract");
  vValue.SetString(sResult.c_str());
  pRst->Update(vColumn,vValue);
  cout<<"finishprocessing"<<tempid<<endl;
  pRst->MoveNext();

 }
 pRst->Close();
 pConn->Close();
 pRst.Release();
 pConn.Release();
 CoUninitialize();
 delete []selectbySpecificId;
 
 ICTCLAS_Exit();


}

原文地址:https://www.cnblogs.com/finallyliuyu/p/1904865.html