VC approach to database based on ADO technology _c language

Source: Internet
Author: User

This article describes the VC based on ADO technology access to the database method. Share to everyone for your reference. Specifically as follows:

First, add in the StdAfx.h file

Copy Code code as follows:
#import "C:/Program Files/common files/system/ado/msado15.dll" no_namespace rename ("EOF", "rseof")

Import the ADO engine.

Second, the database application layer operation

void Cadoexample1dlg::onbtnquery ()
{
  //Todo:add your control notification handler code here
  CoInitialize ( NULL);
  _connectionptr Pconn (__uuidof (Connection));
  _RecordsetPtr PRST (__uuidof (Recordset));
  pconn->connectionstring = "Provider=SQLOLEDB.1; password=123456; Persist Security info=true; User id=sa;initial catalog=db_test;data source=. ";
  Pconn->open ("", "", "", adconnectunspecified);
  PRST = Pconn->execute ("SELECT * from Tb_image", null,adcmdtext);
  while (!prst->rseof)
  {
    (clistbox*) GetDlgItem (idc_list1))->addstring (
      (_bstr_t) prst-> Getcollect ("imageID"));
    Prst->movenext ();
  }
  Prst->close ();
  Pconn->close ();
  Prst.release ();
  Pconn.release ();
  CoUninitialize ();
}

I hope this article on the VC program for everyone to help.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.