如何获取字段名和字段的数据类型
如何用ADO或ADOX获取oracle数据库中字段名和字段的数据类型?
[解决办法]
BOOL CDlgRecordset::GetMicCol()
{
//OnSelchangeComTable();
/*try
{
m_pRecordset=theApp.m_pConnection-> OpenSchema(adSchemaColumns);
while(!(m_pRecordset-> adoEOF))
{
//»ñÈ¡±í¸ñ
_bstr_t col_name = m_pRecordset-> Fields-> GetItem( "TABLE_NAME ")-> Value;
//_bstr_t col_name = m_pRecordset-> Fields-> GetItem(str)-> Value;
//»ñÈ¡±í¸ñÀàÐÍ
_bstr_t col_type = m_pRecordset-> Fields-> GetItem( "COLUMN_TYPE ")-> Value;
//¹ýÂËһϣ¬Ö»Êä³ö±í¸ñÃû³Æ£¬ÆäËûµÄÊ¡ÂÔ
if ( strcmp(((LPCSTR)col_type), "COLUMN ")==0)
{
m_cmbCol.AddString((LPCSTR)col_name);
}
m_pRecordset-> MoveNext();
}
m_pRecordset-> Close();
}*/
_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_cmbTable.GetCurSel();
m_cmbTable.GetLBText(nTable,str);
//strSQL.Format( "SELECT * FROM %s ",str);
strSQL= "select * from " + str;
mStrSQL=strSQL;
/*if(m_pRecordset-> State==1)
{
m_pRecordset-> Close();
}
m_pRecordset-> Open(mStrSQL,
theApp.m_pConnection.GetInterfacePtr(),
adOpenKeyset,
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;
strColName=bstrColName;
nameField=strColName;
m_cmbCol.AddString(nameField);
}
//OnSelchangeComTable();
if(SUCCEEDED(hr))
fields-> Release();//ÊÍÅÖ¸Õë
// ¹Ø±Õ¼Ç¼¼¯
///m_pRecordset-> Close();
/*catch(_com_error e)///²¶×½Òì³£
{
::MessageBox(NULL,e.Description(), "Ìáʾ ",MB_OK);
return FALSE;
}*/
return true;
}