刚才有点乱,再说一遍吧,譬如我有张表是这样的
姓名  主人
小张  小王
小李  小王
小小  小李
     p->strSql = "select * from 表 where 主人like'%“小王”%'"; 
    p->open(ptr);
    int i=0;
    while(!ptr->rsEOF)
{
           n[i]=(LPCTSTR)(_bstr_t)ptr->GetCollect("姓名");
           i++;
           ptr->MoveNext();
}
这样得到的是小张和小李,现在想继续根据所搜来的姓名作为主人,例如小李在表里作为主人,则打开数据库,搜到姓名小小。小张在表里不作为主人,就不再打开数据库。请问大侠们这能实现吗。不知道这样说的明不明白,呵呵
  

解决方案 »

  1.   

    还是不太明白你的意思,不过感觉这个可以用递归来实现void GetName(LPCTSTR lpHost)
    {
        if(lpHost == NULL)
           return ;
        p->strSql = "select * from 表 where 主人 like %'" + lpHost + "'%'"; 
        p->open(ptr); 
        int i=0; 
        while(!ptr->rsEOF) 
        { 
              n[i]=(LPCTSTR)(_bstr_t)ptr->GetCollect("姓名"); 
              GetName(n[i]); 
              i++; 
              ptr->MoveNext(); 
        } }
      

  2.   

    譬如我有张表是这样的 
    姓名  主人 
    小张  小王 
    小李  小王 
    小小  小李 
        p->strSql = "select * from 表 where 主人like'%“小王”%'"; 
        p->open(ptr); 
        int i=0; 
        while(!ptr->rsEOF) 

              n[i]=(LPCTSTR)(_bstr_t)ptr->GetCollect("姓名"); 
              i++; 
              ptr->MoveNext(); 

    这样得到的是小张和小李,现在想继续根据所搜来的姓名作为主人,例如小李在表里作为主人,则打开数据库,搜到姓名小小。小张在表里不作为主人,就不再打开数据库。请问大侠这能实现吗。不知道这样说的明不明白,呵呵 
      

  3.   

    SQL语句改一下就行了:
    select * from 表 where 姓名 in (select 姓名 from 表 where 主人 like '%小王%')
      

  4.   

    一句话即可
    select a, * from 表 a,(select 姓名 from 表 where 主人 like '%小王%') b where a.主人 like '%'+b.姓名+'%'
    unnion all
    select * from 表 where 主人 like '%小王%'
      

  5.   

    错了,应该是select * from 表 where 姓名 in (select 主人 from 表 where 主人 like '%小王%')
      

  6.   

    怪我口齿不清啦,大家帮忙看看这样写对吗
    void jsk::OnSelchangeCombo1() //点击组合框的一栏弹出对话框
    {  int index;
       index=((CComboBox *)GetDlgItem(IDC_COMBO1))->GetCurSel();
       ((CComboBox *)GetDlgItem(IDC_COMBO1))->GetLBText(index,m_str);
       GetName(m_str); 

       qq.DoModal();
       UpdateData(FALSE);
    }
    void jsk::GetName(CString lpHost)
    { _RecordsetPtr ptr;
      CMy11App * p=(CMy11App *)AfxGetApp(); 
      if(lpHost == NULL)
           return ;
      else
          {p->strSql = "select * from TABLE4 where 主人='"+lpHost+"'"; 
           p->open(ptr); 
           int i=0; 
           while(!ptr->rsEOF) 

              n[i]=(LPCTSTR)(_bstr_t)ptr->GetCollect("姓名"); 
              GetName(n[i]); 
              qq.m[i]=n[i];
              i++; 
              ptr->MoveNext(); 
        } 
    }}
      

  7.   

    void jsk::OnSelchangeCombo1() //点击组合框的一栏弹出对话框 
    {  int index; 
      index=((CComboBox *)GetDlgItem(IDC_COMBO1))->GetCurSel(); 
      ((CComboBox *)GetDlgItem(IDC_COMBO1))->GetLBText(index,m_str); 
      GetName(m_str); ////////////////////////////////////////////单步运行到这就报错,不知道什么原因,提示Unhandled   exception   in *.exe:0xc0000005   Access   Voilation”   
      qq.DoModal(); 
      UpdateData(FALSE);