注册 登录
编程论坛 VC++/MFC

获取数据库的表名并交其放入combobox的下拉列表中。程序无错,就是无法实现该功能,求大神指点。

junlove09 发布于 2012-06-25 20:57, 467 次点击
BOOL CAboutDlg::GetTableName()BOOL CAboutDlg::GetTableName();
{

try {
  _RecordsetPtr m_pRecordset=m_pConnection->OpenSchema(adSchemaTables);

  while(!(m_pRecordset->adoEOF)) {   
  // 获取表的名称   
  _bstr_t table_name = m_pRecordset->Fields->GetItem("TABLE_NAME")->Value;
  // 获取表的类型
  _bstr_t table_type = m_pRecordset->Fields->GetItem("TABLE_TYPE")->Value;
  // 添加表的名称
   
  CComboBox combobox;
combobox.AddString((LPCSTR)table_name);//m_cmbTable是表名显示的地方
   
  m_pRecordset->MoveNext();   
  }   
  m_pRecordset->Close();   
  } catch(_com_error e) {
  // Notify the user of errors if any.
  // Pass a connection pointer accessed from the Connection.
  ::MessageBox(NULL,e.Description(),"出错了!",MB_OK);
  return FALSE;
  }

}
1 回复
#2
a4147154402012-06-26 11:37
好像你的  CComboBox combobox;
 是个局部变量,这个函数完成就析构了吧,换成全局的试试,
1