代码如下
m_pRecordset.CreateInstance("ADODB.Recordset");
m_pRecordset->Open(
                  "select distinct Time from Rules order by Time Desc",
                  _variant_t((IDispatch*)m_pMyConnect,true),
                  adOpenStatic,
                  adLockOptimistic,
                  adCmdText);
     while(!m_pRecordset->adoEOF)
     {
  tmp=m_pRecordset->GetCollect(_variant_t((long)0));
  COleDateTime dt = tmp.date;
  int year = dt.GetYear();
  int month=dt.GetMonth();
  int day=dt.GetDay();
  int hour=dt.GetHour();
  int minute=dt.GetMinute();
  int second=dt.GetSecond();
  CString strTmp;
  strTmp.Format("%d-%d-%d %d:%d:%d",year,month,day,hour,minute,second);
         m_ComboCtrl.AddString(strTmp);//运行时失败
   m_pRecordset->MoveNext();
  }
///////////////////////////////////////////////////////////////////////////////
本意是初始ComboBox为空 程序初始化时从数据库中提取按降序提取时间段 插入到CComboBox::m_ComboCtrl里 不知为何错误???

解决方案 »

  1.   

    记不太请了,试试:m_Combo.AddString(strTmp);
      

  2.   

    回syy64(太平洋):放在Dlalog初始化函数中,是这原因么?回xlzxlich(阳光):m_ComboCtrl是跟Combo box关联的CComboBox对象 :-)
      

  3.   

    Return ValueIf the return value is greater than or equal to 0, it is the zero-based index to the string in the list box. The return value is CB_ERR if an error occurs; the return value is CB_ERRSPACE if insufficient space is available to store the new string.如果你确认是这句出的错,那看看到底是什么错误
      

  4.   

    应该不是记录的问题 把m_ComboCtrl.AddString(strTmp)改成m_ComboCtrl.AddString("1")也出错
      

  5.   

    不应该放在Dlalog初始化函数中,因为当时Dialog 还没有创建,你操作它上面的控件当然不对啦。你不信可以在Dialog 上放一个BUTTON,然后在Button的click事件中加入m_ComboCtrl.AddString(strTmp);。
      

  6.   

    to superpeel() 
    是这问题了,那初始化时就要显示该怎么做?
      

  7.   

    把m_ComboCtrl.AddString(strTmp);加在DoDataExchange的最后面中就可以啦:)
      

  8.   

    可以放在OnInitDialog里面的.说不行的.只是他菜.
      

  9.   

    BOOL CComboxDlg::OnInitDialog()
    {
    CDialog::OnInitDialog(); // Set the icon for this dialog.  The framework does this automatically
    //  when the application's main window is not a dialog
    SetIcon(m_hIcon, TRUE); // Set big icon
    SetIcon(m_hIcon, FALSE); // Set small icon

    // TODO: Add extra initialization here
    box.AddString("A");
    box.AddString("B");
    box.AddString("C");
    box.SetCurSel(0);
    return TRUE;  // return TRUE  unless you set the focus to a control
    }如果你认为这样是不行的话.那你真的很菜.
      

  10.   

    to superpeel  abuseyoudna1981
    解决了 两位的方法都ok的 thanks 
    ps:
    to abuseyoudna1981
    superpeel 的意思是放在Dialog的OnInitDialog里不行的 我也很菜 说不清楚 呵呵菜无所谓 我要的是热心 3x