我先创建了一个程序,对应了数据库中的一个表,这个表中有一列每一个字段是不重复的,我把它加入到了一个ccombobox里边,然后我想根据在对话框中选定的这个字段来打开另外一个表,把另外一个表的某一列的字段添加到该对话框上另外一个combobox中去,今天上午试了一个上午总是不行,不知道哪位能知道一下小弟?
我对第一个ccombobox控件添加了一个onseleok函数。

解决方案 »

  1.   

    添加消息CBN_SELCHANGE的响应函数
      

  2.   

    ON_CBN_SELENDOK(IDC_PRODUCT, OnSelendokProduct)//消息处理映射void CFeedBackDlg::OnSelendokProduct() 
    {
    // TODO: Add your control notification handler code here
    CString strProduct;
    m_Product.GetLBText(m_Product.GetCurSel(),strProduct);
    if(strProduct.IsEmpty()){
    AfxMessageBox("请选取产品名称!");
    return;
    }
    CString strSQL;
    strSQL.Format("SELECT DISTINCT 产品规格 FROM 业务订单表\
    WHERE 产品名称='%s'",
    strProduct);
    try{
    theApp.m_pSet->Open(strSQL.AllocSysString(),
    theApp.m_pConn.GetInterfacePtr(),
    adOpenDynamic,
    adLockOptimistic,
    adCmdText);
    if(theApp.m_pSet->BOF&&theApp.m_pSet->adoEOF){
    theApp.m_pSet->Close();
    return;
    }
    else{
    theApp.m_pSet->MoveFirst();
    while(!theApp.m_pSet->adoEOF){
    if(theApp.m_pSet->GetCollect("产品规格").vt!=VT_NULL){
    CString strVal=theApp.m_pSet->GetCollect("产品规格").bstrVal;
    if(!strVal.IsEmpty()){
    m_Spec.AddString(strVal);
    }
    }
    theApp.m_pSet->MoveNext();
    }
    theApp.m_pSet->Close();
    }
    }
    catch(_com_error& e){
    AfxMessageBox(e.Description());
    }
    }
      

  3.   

    CBN_SELCHANGE获得字符串,然后sql连接