// Add "About..." menu item to system menu. m_pRecordset.CreateInstance(__uuidof(Recordset)); try { m_pRecordset->Open("SELECT * FROM myado", theApp.m_pConnection.GetInterfacePtr(), adOpenDynamic, adLockOptimistic, adCmdText); } catch(_com_error *e) { AfxMessageBox(e->ErrorMessage()); } return TRUE; // return TRUE unless you set the focus to a control }for(i=0;i<m_DWordArray.GetSize();i++) { m_pRecordset->AddNew(); strTemp.Format("%d.%d.%d.%d",uSourceInt[0],uSourceInt[1],uSourceInt[2],uSourceInt[3]); // m_lstPack.SetItemText(i,2,strTemp); // myFile.Write(strTemp+"\r",strlen(strTemp)+2); m_pRecordset->PutCollect("SourceIP", _variant_t(strTemp)); m_pRecordset->Update(); }貌似可以的,插入2000条大概需要10S左右
CString strSql;// Access Data Base operate String CString FileName = ff.GetFileName(); FileName.Replace("'","''"); CString FilePath = ff.GetFilePath();
FilePath.Replace("'","''"); strSql.Format("insert into File([filename],[path],[filesize],[modified],[lastaccess],[create]) values('%s','%s','%d','%d','%d','%d')" ,FileName,FilePath,rStatus.m_size,rStatus.m_mtime ,rStatus.m_atime,rStatus.m_ctime);
//Execute
try{ //Thread Error Link Error ; m_pConnection->Execute((LPCTSTR)strSql,&vFieldName,adCmdText); }catch(_com_error e) { AfxMessageBox(e.Description()); long errorCode=e.WCode(); if(3127==errorCode) AfxMessageBox("表不存在"); if(3092==errorCode) AfxMessageBox("表已经存在"); return; } 非常的慢,怎么搞能快啊.问题与他的类似啊.
如果是外部的数据貌似是要用insert into一条一条插的
效率太低了瓶颈就在数据插入上
速度还是比较快,2000条估计就10S
不过数据采集和数据写入数据库是同时进行的
Command要设一下Prepared 属性。
还不行就用存储过程了。你两个都试试。
BOOL CFileTestDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
m_pRecordset.CreateInstance(__uuidof(Recordset));
try
{
m_pRecordset->Open("SELECT * FROM myado", theApp.m_pConnection.GetInterfacePtr(), adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(_com_error *e)
{
AfxMessageBox(e->ErrorMessage());
}
return TRUE; // return TRUE unless you set the focus to a control
}for(i=0;i<m_DWordArray.GetSize();i++)
{
m_pRecordset->AddNew();
strTemp.Format("%d.%d.%d.%d",uSourceInt[0],uSourceInt[1],uSourceInt[2],uSourceInt[3]);
// m_lstPack.SetItemText(i,2,strTemp);
// myFile.Write(strTemp+"\r",strlen(strTemp)+2);
m_pRecordset->PutCollect("SourceIP", _variant_t(strTemp));
m_pRecordset->Update();
}貌似可以的,插入2000条大概需要10S左右
CString FileName = ff.GetFileName();
FileName.Replace("'","''");
CString FilePath = ff.GetFilePath();
FilePath.Replace("'","''");
strSql.Format("insert into File([filename],[path],[filesize],[modified],[lastaccess],[create]) values('%s','%s','%d','%d','%d','%d')"
,FileName,FilePath,rStatus.m_size,rStatus.m_mtime
,rStatus.m_atime,rStatus.m_ctime);
//Execute
try{
//Thread Error Link Error ;
m_pConnection->Execute((LPCTSTR)strSql,&vFieldName,adCmdText);
}catch(_com_error e)
{
AfxMessageBox(e.Description());
long errorCode=e.WCode();
if(3127==errorCode) AfxMessageBox("表不存在");
if(3092==errorCode) AfxMessageBox("表已经存在");
return;
}
非常的慢,怎么搞能快啊.问题与他的类似啊.