XiaoHui.net 笑汇程序员论坛首页
工作并快乐着,职业并休闲着
寻梦的岁月从不言辛苦几许,
不问收获几多……
» 游客:  申请新用户 | 登录 | 会员 | 统计 | 帮助 » XiaoHui.Net 笑汇程序员论坛 | 纯文字版 | 全站索引 | XiaoHui.com


[数据库] SQL查询问题

RSS 订阅当前论坛  

上一主题 下一主题
     

标题: [数据库] SQL查询问题  
 
百年孤独
小水手
Rank: 1



UID 19889
精华 0
积分 14
帖子 14
阅读权限 10
注册 2003-8-8
状态 离线
SQL查询问题

代码如下:
HRESULT hr;
        CString sql;
        _variant_t vWuyeManageOwnerName;
        _variant_t vWuyeManageUptown;
        _variant_t vWuyeManageRidgepoleNumber;
        _variant_t vWuyeManageApartment;
        _variant_t vWuyeManageRoom;
        _variant_t vWuyeManageStructrue;
        _variant_t vWuyeManageArea;
        _variant_t vWuyeManageRateStandard;
        _variant_t vWuyeManagePhone;
        _variant_t vWuyeManageIDCard;
        _variant_t vWuyeManageUnit;
        _variant_t vWuyeManagePutinTime;
        sql.Format("SELECT * FROM OwnerInfo WHERE OwnerName = '%s' ", m_strWuyeManageQueryName);
        try
        {
          hr = m_pRecordsetofOwnerInfo.CreateInstance("ADODB.Recordset");
      if(SUCCEEDED(hr))
          {
                  hr = m_pRecordsetofOwnerInfo->Open((LPCTSTR)sql, _variant_t(theApp.m_pConnection.GetInterfacePtr()),
                                          adOpenDynamic, adLockOptimistic, adCmdText);
          }
        }
    catch(_com_error e)                                     //捕捉异常
    {
                CString errormessage;
                errormessage.Format("打开表失败!\r\n错误信息:%s", e.ErrorMessage());
                AfxMessageBox(errormessage);                        //显示错误信息
        }
        try
        {
                m_strWuyeManageOwnerInfoShow.DeleteAllItems();
                m_pRecordsetofOwnerInfo->MoveFirst();
                while(!m_pRecordsetofOwnerInfo->adoEOF)
                {
                        int nItem;

                        vWuyeManageOwnerName = m_pRecordsetofOwnerInfo->GetCollect("OwnerName");
                    vWuyeManageUptown = m_pRecordsetofOwnerInfo->GetCollect("Uptown");
                    vWuyeManageRidgepoleNumber = m_pRecordsetofOwnerInfo->GetCollect("RidgepoleNumber");
                        vWuyeManageApartment = m_pRecordsetofOwnerInfo->GetCollect("Apartment");
                        vWuyeManageRoom = m_pRecordsetofOwnerInfo->GetCollect("Room");
                        vWuyeManageStructrue = m_pRecordsetofOwnerInfo->GetCollect("Structrue");
                        vWuyeManageArea = m_pRecordsetofOwnerInfo->GetCollect("Area");
                        vWuyeManageRateStandard = m_pRecordsetofOwnerInfo->GetCollect("RateStandard");
                        vWuyeManagePhone = m_pRecordsetofOwnerInfo->GetCollect("Phone");
                        vWuyeManageIDCard = m_pRecordsetofOwnerInfo->GetCollect("IDCard");
                        vWuyeManageUnit = m_pRecordsetofOwnerInfo->GetCollect("Unit");
                        vWuyeManagePutinTime = m_pRecordsetofOwnerInfo->GetCollect("PutinTime" );

                        //在列表显示查找到的结果

                        nItem = m_strWuyeManageOwnerInfoShow.InsertItem(0xffff,(_bstr_t)vWuyeManageOwnerName);  
                        m_strWuyeManageOwnerInfoShow.SetItem(nItem,1,1,(_bstr_t)vWuyeManageUptown,NULL,0,0,0);
                        m_strWuyeManageOwnerInfoShow.SetItem(nItem,2,1,(_bstr_t)vWuyeManageRidgepoleNumber,NULL,0,0,0);
                        m_strWuyeManageOwnerInfoShow.SetItem(nItem,3,1,(_bstr_t)vWuyeManageApartment,NULL,0,0,0);
                        m_strWuyeManageOwnerInfoShow.SetItem(nItem,4,1,(_bstr_t)vWuyeManageRoom,NULL,0,0,0);
                        m_strWuyeManageOwnerInfoShow.SetItem(nItem,5,1,(_bstr_t)vWuyeManageStructrue,NULL,0,0,0);
                        m_strWuyeManageOwnerInfoShow.SetItem(nItem,6,1,(_bstr_t)vWuyeManageArea,NULL,0,0,0);
                        m_strWuyeManageOwnerInfoShow.SetItem(nItem,7,1,(_bstr_t)vWuyeManageRateStandard,NULL,0,0,0);
                        m_strWuyeManageOwnerInfoShow.SetItem(nItem,8,1,(_bstr_t)vWuyeManagePhone,NULL,0,0,0);
                        m_strWuyeManageOwnerInfoShow.SetItem(nItem,9,1,(_bstr_t)vWuyeManageIDCard,NULL,0,0,0);
                        m_strWuyeManageOwnerInfoShow.SetItem(nItem,10,1,(_bstr_t)vWuyeManageUnit,NULL,0,0,0);
                        m_strWuyeManageOwnerInfoShow.SetItem(nItem,11,1,(_bstr_t)vWuyeManagePutinTime,NULL,0,0,0);

                        m_pRecordsetofOwnerInfo->MoveNext();
                }
            m_strWuyeManageOwnerName = _T("");
                m_strWuyeManageUptown = _T("");
                m_strWuyeManageRidgepoleNumber = _T("");
                m_strWuyeManageApartment = _T("");
                m_strWuyeManageRoom = _T("");
                m_strWuyeManageStructrue = _T("");
                m_strWuyeManageArea = _T("");
                m_strWuyeManageRateStandard = _T("");
                m_strWuyeManagePhone = _T("");
                m_strWuyeManageIDCard = _T("");
                m_strWuyeManageUnit = _T("");
                m_strWuyeManagePutinTime = COleDateTime::GetCurrentTime();
               
                GetDlgItem(IDD_WUYE_MANAGE_QUERY)->EnableWindow(FALSE);
                GetDlgItem(IDD_WUYE_MANAGE_QUERYRETURN)->EnableWindow(TRUE);
               
        }
        catch(_com_error e)
        {
                CString errormessage;
                errormessage.Format("打开表失败!\r\n错误信息:%s", e.ErrorMessage());
                AfxMessageBox(errormessage);                        //显示错误信息
        }
请看看出了什么问题。。查询后显示表打开错误。。。
2006-4-21 11:11#1
查看资料  Blog  发短消息  顶部
     


  可打印版本 | 推荐给朋友 | 订阅主题 | 收藏主题  


 


所有时间为 GMT+8, 现在时间是 2008-12-3 05:45 Powered by Discuz! 4.1.0 清除 Cookies - XiaoHui.Net 笑汇程序员论坛 - Archiver