vc6的pRecordset如何获得所有字段的名称和数据类型?
谢谢!
[解决办法]
BOOL CDlgTest::GetMicFields()
{
_bstr_t mStrSQL;
CString strSQL;
CString strColName;
BSTR bstrColName;
long ColCount,i;
Field * field = NULL;
HRESULT hr;
Fields * fields = NULL;
LPCTSTR nameField;
CString str;
int nTable=m_cmbAlTab.GetCurSel();
m_cmbAlTab.GetLBText(nTable,str);
//strSQL.Format( "SELECT * FROM %s ",str);
strSQL= "select * from " + str;
mStrSQL=strSQL;
m_pRecordset-> Open(mStrSQL,
theApp.m_pConnection.GetInterfacePtr(),
adOpenDynamic,
adLockOptimistic,
adCmdText);
hr=m_pRecordset-> get_Fields(&fields);//µÃµ½¼Ç¼¼¯µÄ×ֶμ¯ºÏ
if(SUCCEEDED(hr))
fields-> get_Count(&ColCount);//µÃµ½¼Ç¼¼¯µÄ×ֶμ¯ºÏÖеÄ×ֶεÄ×ܸöÊý
for(i=0;i <ColCount;i++)
{
fields-> Item[i]-> get_Name(&bstrColName);//µÃµ½¼Ç¼¼¯ÖеÄ×Ö¶ÎÃû
UINT uType=fields-> Item[i]-> Type;
fields-> Item[i]-> DefinedSize;
strColName=bstrColName;
nameField=strColName;
//m_cmbCol.AddString(nameField);
m_List.SetItemText(i,0,nameField);
m_List.SetItemText(i,1,(LPCTSTR)uType);
}
//OnSelchangeComTable();
if(SUCCEEDED(hr))
fields-> Release();//ÊÍ·ÅÖ¸Õë
// ¹Ø±Õ¼Ç¼¼¯
m_pRecordset-> Close();
return true;
}