获去列信息 _variant_t 装换为CString

来源:互联网 发布:免费象棋开局软件 编辑:程序博客网 时间:2024/05/16 23:45

        int nCount = 0;

        //开始打开表,以便得到表的结构       
        pApp->m_pRecordset->Open("表名称", pApp->m_pConnection.GetInterfacePtr(), adOpenDynamic, adLockOptimistic, adCmdTable);

        FieldsPtr fds = pApp->m_pRecordset->GetFields();

        EmptyList();

        //依次读取字段,并显示
        //字段名
        m_ctlList.InsertColumn(0, _T("   "), LVCFMT_LEFT, 40);
        for(int i = 0; i < fds->GetCount(); i++)
        {
            FieldPtr fd = fds->GetItem(_variant_t(short(i)));
            if(fd->Value.vt != NULL)
            {
                CString strName((LPCTSTR)fd->GetName());
                m_ctlList.InsertColumn(i+1, strName, LVCFMT_LEFT, strName.GetLength()*10+10);
            }
            else
            {
                m_ctlList.InsertColumn(i+1, _T(""), LVCFMT_LEFT, 10+10);
            }
           
        }

        m_ctlList.InsertItem(0, _T("类型"));
        //字段类型
        for(i = 0; i < fds->GetCount(); i++)
        {
            FieldPtr fd = fds->GetItem(_variant_t(short(i)));
            m_ctlList.SetItemText(0, i+1, GetType(fd->GetType()));
           
        }
        m_ctlList.InsertItem(1, _T("大小"));
        //字段大小
        for(i = 0; i < fds->GetCount(); i++)
        {
            FieldPtr fd = fds->GetItem(_variant_t(short(i)));
           
            CString strName;
            strName.Format(_T("%ld"), fd->GetDefinedSize());
            m_ctlList.SetItemText(1, i+1, strName);
           
        }
       
        pApp->m_pRecordset->Close();


 //_variant_t 转换为 CString 
  cspdprice = (LPCTSTR)(_bstr_t)vt_pdprice;

原创粉丝点击