首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

怎么获取字段名和字段的数据类型

2012-02-24 
如何获取字段名和字段的数据类型如何用ADO或ADOX获取oracle数据库中字段名和字段的数据类型?[解决办法]BOO

如何获取字段名和字段的数据类型
如何用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);//&micro;&Atilde;&micro;&frac12;&frac14;&Ccedil;&Acirc;&frac14;&frac14;&macr;&Ouml;&ETH;&micro;&Auml;×&Ouml;&para;&Icirc;&Atilde;&ucirc;
//UINT uType=fields-> Item[i]-> Type;
strColName=bstrColName;
nameField=strColName;
m_cmbCol.AddString(nameField);

}
//OnSelchangeComTable();
if(SUCCEEDED(hr))
fields-> Release();//&Ecirc;&Iacute;·&Aring;&Ouml;&cedil;&Otilde;&euml;


// &sup1;&Oslash;±&Otilde;&frac14;&Ccedil;&Acirc;&frac14;&frac14;&macr;
///m_pRecordset-> Close();


/*catch(_com_error e)///&sup2;&para;×&frac12;&Ograve;ì&sup3;&pound;
{
::MessageBox(NULL,e.Description(), "&Igrave;á&Ecirc;&frac34; ",MB_OK);


return FALSE;
}*/

return true;

}

热点排行