Home Database Mysql Tutorial ADO实现Access数据库表的遍历和字段的遍历

ADO实现Access数据库表的遍历和字段的遍历

Jun 07, 2016 pm 03:49 PM
access Field accomplish database Enter Traverse

欢迎进入C/C++编程社区论坛,与200万技术人员互动交流 >>进入 网络上鲜有VC版的相关代码,今日学习了VC利用ADO操纵数据库部分。查了一下MSDN写了以下代: 遍历用户表的代码: CoInitialize(NULL); _ConnectionPtr pconn(__uuidof(Connection)); _RecordsetPtr

欢迎进入C/C++编程社区论坛,与200万技术人员互动交流 >>进入

   网络上鲜有VC版的相关代码,今日学习了VC利用ADO操纵数据库部分。查了一下MSDN写了以下代:

遍历用户表的代码:

  CoInitialize(NULL);
 _ConnectionPtr pconn(__uuidof(Connection));
 _RecordsetPtr prs(__uuidof(Recordset));
    pconn->ConnectionString=\"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\\\VC\\\\Lesson20\\\\db.mdb;Persist Security Info=False\";
 pconn->Open(\"\",\"\",\"\",adConnectUnspecified);
    prs=pconn->OpenSchema(adSchemaTables);
 while (!prs->adoEoF)
 {
  if (!strcmp((_bstr_t)prs->Fields->GetItem(\"TABLE_TYPE\")->Value,\"TABLE\"))
  {
   m_tablelist.AddString((_bstr_t)prs->Fields->GetItem(\"TABLE_NAME\")->Value);
      prs->MoveNext();
  }
  else
   prs->MoveNext();
 }
 prs->Close();
 pconn->Close();
    prs.Release();
 pconn.Release();
   CoUninitialize();

遍历字段的代码:

CString str;
 m_tablelist.GetText(m_tablelist.GetCurSel(),str);//通过表列表框得到表的名称
 if (m_columnlist.GetCount()>0)
 {
  m_columnlist.ResetContent();
 }
 CoInitialize(NULL);
 _ConnectionPtr pconn(__uuidof(Connection));
 _RecordsetPtr prs(__uuidof(Recordset));
    pconn->ConnectionString=\"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\\\VC\\\\Lesson20\\\\db.mdb;Persist Security Info=False\";
 pconn->Open(\"\",\"\",\"\",adConnectUnspecified);
   prs=pconn->OpenSchema(adSchemaColumns);
 while (!prs->adoEoF)
 {
  if (!strcmp((_bstr_t)prs->Fields->GetItem(\"TABLE_NAME\")->Value,(_bstr_t)(LPCTSTR)str))
  {
   int index=m_columnlist.GetCount();
  // m_columnlist.AddString((_bstr_t)prs->Fields->GetItem(\"COLUMN_NAME\")->Value);
            m_columnlist.InsertString(index,(_bstr_t)prs->Fields->GetItem(\"COLUMN_NAME\")->Value);
   prs->MoveNext();
  }
  else
   prs->MoveNext();
 }
 prs->Close();
 pconn->Close();
    prs.Release();
 pconn.Release();
   CoUninitialize(); 

ADO实现Access数据库表的遍历和字段的遍历

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to disable background applications in Windows 11_Windows 11 tutorial to disable background applications How to disable background applications in Windows 11_Windows 11 tutorial to disable background applications May 07, 2024 pm 04:20 PM

How to disable background applications in Windows 11_Windows 11 tutorial to disable background applications

How to convert deepseek pdf How to convert deepseek pdf Feb 19, 2025 pm 05:24 PM

How to convert deepseek pdf

How does the Java reflection mechanism modify the behavior of a class? How does the Java reflection mechanism modify the behavior of a class? May 03, 2024 pm 06:15 PM

How does the Java reflection mechanism modify the behavior of a class?

How to cross-domain iframe in vue How to cross-domain iframe in vue May 02, 2024 pm 10:48 PM

How to cross-domain iframe in vue

Common exception types and their repair measures in Java function development Common exception types and their repair measures in Java function development May 03, 2024 pm 02:09 PM

Common exception types and their repair measures in Java function development

Detailed tutorial on establishing a database connection using MySQLi in PHP Detailed tutorial on establishing a database connection using MySQLi in PHP Jun 04, 2024 pm 01:42 PM

Detailed tutorial on establishing a database connection using MySQLi in PHP

How to read dbf file in oracle How to read dbf file in oracle May 10, 2024 am 01:27 AM

How to read dbf file in oracle

iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos Jul 18, 2024 am 05:48 AM

iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos

See all articles