cannot judge based on the code you presented, but to remove the errors, make the following changes://*.h文件
extern CAdodc g_AdoDC;    //ADODC控件
extern CDataGrid g_DataGrid;  //DataGrid控件
extern  UINT QueryDB(LPVOID pParam);//*.cpp文件
.....
CAdodc g_AdoDC;    //ADODC控件
CDataGrid g_DataGrid;  //DataGrid控件void CBill121Dlg::DoDataExchange(CDataExchange* pDX)
{

解决方案 »

  1.   

    估计是你上面的头文件还被include到了其他地方,线程的使用好像没什么错,编译器报的错也不是关于线程的
      

  2.   

    karma(无为):
         程序编译连接都通过了,但运行进入线程QueryDB()时就出错了
    UINT QueryDB(LPVOID pParam)
    {
    g_AdoDC.Refresh();   //运行到这里出错
    g_DataGrid.SetRefDataSource(g_AdoDC.GetDSCCursor());
    return 0;
    }请问各位程序该怎么改
      

  3.   

    threads():
        现在程序能运行了,但线程里出错了,请问改如何改。
      

  4.   

    你可以看看CCriticalSection类的用法。
      

  5.   

    需要传递给子线程指针以便调用主线程中的数据,因为你要调用数个变量,传递主线程指针比较方便。作修改如下:
    UINT QueryDB(LPVOID pParam)
    {
    CBill121Dlg *pDlg = (CBill121Dlg*)pParam; //modify
    pDlg->g_AdoDC.Refresh();//modify
    pDlg->g_DataGrid.SetRefDataSource(g_AdoDC.GetDSCCursor());//modify
    return 0;
    }
    .....
    void CBill121Dlg::OnQuery() 
    {
    .....
    g_AdoDC.SetConnectionString(strConnectionString);
    g_AdoDC.SetCommandType(1);
    g_AdoDC.SetRecordSource(SQL);
    AfxBeginThread(QueryDB,this,THREAD_PRIORITY_NORMAL);//modify
    }
      

  6.   

    fishskin(鱼皮):
         能否说说具体怎样做呢
      

  7.   

    ydogg(灰毛兔频频):
        程序按你的改了,但同样运行到g_AdoDC.Refresh()就出错了
      

  8.   

    fishskin(鱼皮):
        我将程序改为CCriticalSection g_cs;UINT QueryDB(LPVOID pParam)
    {
    // g_AdoDC.Refresh();
    // g_DataGrid.SetRefDataSource(g_AdoDC.GetDSCCursor());
    CBill121Dlg *pDlg = (CBill121Dlg*)pParam; 

    g_cs.Lock();
    pDlg->g_AdoDC.SetConnectionString(pDlg->m_strConnectionString);
    pDlg->g_AdoDC.SetCommandType(1);
    pDlg->g_AdoDC.Refresh();   //运行到这里出错 
    pDlg->g_DataGrid.SetRefDataSource(pDlg->g_AdoDC.GetDSCCursor());
    g_cs.Unlock();
    return 0;
    }
    错误提示:Unhandled exception in Bill121.exe(KERNEL32.DLL):0xE06D73263:Microsoft C++ Exception
      

  9.   

    错误信息是什么?
    你的
    CAdodc g_AdoDC;    //ADODC控件
    CDataGrid g_DataGrid;  //DataGrid控件
    定义在何处?
      

  10.   

    试试看这样:把g_AdoDC.Refresh(),g_AdoDC.GetDSCCursor()都放到主线程然后将g_AdoDC.GetDSCCursor()的返回值传到子线程里给g_DataGrid.SetRefDataSource()可惜我不熟悉这两个类的使用,你的本意应该是想把响应前端的请求跟后台的数据库操作分开吧?不过你原来这样写的话如果CAdodc不支持多线程的话就有一个同步的问题了。
    另外CriticalSection的用法不对,主线程中访问共享资源的代码也应放入其中。
      

  11.   

    threads():
        将g_AdoDC.Refresh()放在主线程,那么QueryDB(LPVOID pParam)子线程的意义就不大了,因为程序费时间主要在g_AdoDC.Refresh()(这是数据库查询,很费时间)。但如果只有一个主线程的时候,当进行查询的时,程序就不能作其他的操作。我建立QueryDB(LPVOID pParam)子线程主要为了想在程序进行查询的时候,还能响应其他的操作。
      

  12.   

    没用过adodc,但我怀疑是不是还没打开DB啊?不是首先要OPEN一下的么?