ADO Execute和要查询数据库怎么做
m_pConnection.CreateInstance(__uuidof(Connection));m_pRecordset.CreateInstance(__uuidof(Recordset));
m_pCommand.CreateInstance(__uuidof(Command));
// 连接数据源为"Database Example For VC++"
try
{
m_pConnection->Open("Provider=MSDAORA.1;User ID=test;\
Data Source=oracle;Persist Security Info=False","test","test",0);
}
catch(...)
{
AfxMessageBox("连接数据库失败.",0,-1);
}
AfxMessageBox("连接数据库成功.",0,1);
_RecordsetPtr precordset = NULL;
precordset = m_pConnection->OpenSchema(adSchemaColumns);
// precordset = m_pConnection->Execute("select * from student",NULL,adCmdUnknown);
//这里如果用Execute该怎么写,SQL查询语句怎么写,我这样写不行。。
CListCtrl& m_ListCtrl = GetListCtrl();
CString strHeader[3] = {"序号","TABLE_NAME","COLUMN_NAME"};
for (int i=0; i<3; i++)
m_ListCtrl.InsertColumn( i, strHeader[i], LVCFMT_LEFT, 120);
int nItem = 0;
CString str;
_bstr_t value;
while(!(precordset->adoEOF)) {
str.Format("%d", nItem+1 );
m_ListCtrl.InsertItem( nItem, str );
for (int i=1; i<3; i++){
value = precordset->Fields->GetItem((_bstr_t)(LPCSTR)strHeader[i])->Value;
m_ListCtrl.SetItemText( nItem, i, value );
}
precordset->MoveNext();
nItem++;
}
precordset->Close();