MFC ADO连接Oracle12c数据库 类库文件
时间:2021-07-01 10:21:17
帮助过:54人阅读
//--------查询示例 start--------
std::
string sql =
"select * from username";
adoreader =
ado.ExecuteReader(sql);
_variant_t strz,value;
CString stry;
int nItem =
0;
_RecordsetPtr m_recordSetPtr =
adoreader.m_recordSetPtr;
FieldsPtr flds = m_recordSetPtr->GetFields();
//获取表的列的个数
_variant_t Index;
Index.vt =
VT_I2;
//--------动态添加头部标题 start--------
//m_ListCtrl->InsertColumn(0,"序号",LVCFMT_LEFT,50);
for (
int i =
0;i<(
int)flds->GetCount();i++
)
{
Index.iVal =
i;
//m_ListCtrl->InsertColumn(i+1,(LPSTR)flds->GetItem(Index)->GetName(),LVCFMT_LEFT,100);
}
//--------动态添加头部标题 end--------
//--------添加行数据 start--------
while(m_recordSetPtr->adoEOF == FALSE)
//m_pRecordset->adoEOF
{
stry.Format(_T("%d"),nItem+
1);
//m_ListCtrl->InsertItem(nItem,stry);
for (
int i =
0;i < (
int)m_recordSetPtr->Fields->Count;i++
)
{
Index.iVal =
i;
strz = flds->GetItem(Index)->
GetName();
value = m_recordSetPtr->
GetCollect(strz);
if (value.vt !=
VT_NULL)
{
//m_ListCtrl->SetItemText(nItem,i+1,(LPCSTR)(_bstr_t)value);
}
else
{
//m_ListCtrl->SetItemText(nItem,i+1,"");
}
}
m_recordSetPtr->
MoveNext();
nItem++
;
}
m_recordSetPtr->
Close();
adoreader.recordClose();
//--------添加行数据 end --------
//--------查询示例 end--------
//--------新增示例 start --------
std::
string sql =
"insert into username(ID,NAME) values(‘4‘,‘name4‘)";
int ret =
0;
ret =
ado.ExecuteNonQuery(sql);
//--------新增示例 end --------
//--------编辑示例 start --------
sql =
"update username set name=‘namemax‘ where id=‘4‘";
ret =
ado.ExecuteNonQuery(sql);
//--------编辑示例 end --------
//--------删除示例 start --------
sql =
"delete from username where id=‘4‘";
ret =
ado.ExecuteNonQuery(sql);
//--------删除示例 end --------
MFC ADO连接Oracle12c数据库 类库文件
标签: