我用Access2000做了一个数据库,原本里面有三列,现在我重新设计,添加了两列,然后在程序中相应的位置添加连接这两列数据的语句。(用list控件显示)运行程序,出现错误。将新添加的语句注释掉,程序运行正常。请问为什么呀?搞了一天了都没整明白,是不是还要重新连接数据库啊?我用的是相对路径,改成绝对路径也不行。高手来帮帮忙吧。

解决方案 »

  1.   

    连接数据库和获取数据集是分开的,你数据库连接肯定没有问题,是获取数据集错了,贴你的sql语句吧。
    或许是这样,你本想的到 a,b,c  但是你的语句却写成了这样 select a,b from 
    然后 你还getcollect(“c”)了,这样当然就错了。语句要写成select a,b,c from 
      

  2.   

    void CToolDlg::AddToGrid()
    {
        ADOConn m_AdoConn;
    //打开数据库连接
    m_AdoConn.OnInitADOConn();
    CString sql;
    sql.Format("select * from tool order by 刀具编号 desc");
    _RecordsetPtr m_pRecordset;
    //打开记录集
    m_pRecordset=m_AdoConn.GetRecordset((_bstr_t)sql);
    //遍历记录集
    while(m_AdoConn.m_pRecordset->adoEOF==0)
    {
    m_grid.InsertItem(0,"");//插入行
    //将记录集字段中的记录添加到List Control控件中
            m_grid.SetItemText(0,0,(char*)(_bstr_t)m_pRecordset->GetCollect("刀具编号"));
    m_grid.SetItemText(0,1,(char*)(_bstr_t)m_pRecordset->GetCollect("刀具名称"));
    m_grid.SetItemText(0,2,(char*)(_bstr_t)m_pRecordset->GetCollect("库存量"));
    m_grid.SetItemText(0,3,(char*)(_bstr_t)m_pRecordset->GetCollect("等等"));
    //使记录集指针指向下一记录
    m_pRecordset->MoveNext();
    }
    //断开数据库连接
    m_AdoConn.ExitConnect();
    }
    以上是我的遍历集函数代码,原来只有前三个,等我加上“等等”这一列以后,就不行了
      

  3.   

    下面这句:
    m_grid.SetItemText(0,3,(char*)(_bstr_t)m_pRecordset->GetCollect("等等"));
    注释掉就运行正常,否则就会出错。