现在有个程序是不断地收集数据然后往数据库里插,如何提高插入速度,现在瓶颈就在数据插入上,
那位高手有好办法快速插入数据

解决方案 »

  1.   

    你的数据是哪来的,如果不是表间数据的拷贝
    如果是外部的数据貌似是要用insert into一条一条插的
      

  2.   

    就是insert into一条一条插的
    效率太低了瓶颈就在数据插入上
      

  3.   

    另外,如果你是用ADO的Connection对象的Execute方法执行插入语句的话不要一句插入语句执行一次多几条写在一起一起通过Execute执行,多个语句之间要用回车分开
      

  4.   

    我用ADO 的INSERT 方法来做的的
    速度还是比较快,2000条估计就10S
    不过数据采集和数据写入数据库是同时进行的
      

  5.   

    用Command和Parameter,这样就不用每次插入时解析SQL语句了。
    Command要设一下Prepared 属性。
    还不行就用存储过程了。你两个都试试。
      

  6.   

    首先在初始窗口中用SQL语句,然后在循环语句中AddNew()
    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左右
      

  7.   

    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;

    非常的慢,怎么搞能快啊.问题与他的类似啊.