亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

MFC用ado方法和數據庫連接后,怎么取得數據

MFC用ado方法和數據庫連接后,怎么取得數據

江戶川亂折騰 2019-03-14 10:10:32
MFC用ado方法和數據庫連接后,怎么取得數據
查看完整描述

2 回答

?
波斯汪

TA貢獻1811條經驗 獲得超4個贊

pCommand->CommandText = "SELECT * FROM XXX";
pRecordset=pCommand->Execute(NULL,NULL,adCmdText);
這就會執行那句select語句。
至于你說的放哪,就又你自己決定,我猜你是想放列表控件里面。這樣的話 你就直接顯示在列表控件中就是了。
代碼如下:
int cols = pRecordset->GetFields()->Count;//獲取列數
if (data_name!=NULL)
{
delete []data_name;
}
data_name = new CString[cols];
_variant_t get_name;
//讀取字段名
for (int i=0;i<cols;i++)
{
get_name = pRecordset->GetFields()->GetItem(_variant_t(short(i)))->GetName();
if (get_name.vt==VT_NULL)
{
data_name[i].Empty();
}
else
data_name[i] = (LPCTSTR)(_bstr_t)get_name;
int nWidth = listctrl.GetStringWidth(data_name[i]) + 60;
listctrl.InsertColumn(i, data_name[i], LVCFMT_LEFT, nWidth);
}
int nCount =0;
//獲取數據
CString lptext;
bool f =false;
CString k("0");
while (!pRecordset->GetadoEOF ())
{
listctrl.InsertItem(nCount,k);
for (int j=0;j<cols;j++)
{
get_name = pRecordset->GetFields()->GetItem(_variant_t(short(j)))->GetValue();
if (get_name.vt==VT_NULL)
{
lptext.Empty();
}
else
lptext = (LPCTSTR)(_bstr_t)get_name;

listctrl.SetItemText(nCount,j,lptext);
}
pRecordset->MoveNext();
nCount++;
}
pRecordset->Close();

 


查看完整回答
反對 回復 2019-03-20
  • 2 回答
  • 0 關注
  • 1318 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號