C + + reads data from the database and displays the data on the Treectrl on the interface

Source: Internet
Author: User
Tags dsn odbc

The Oracle database reads the data as follows:


The code is as follows:

Constructs a node struct area{long ID;   Long parent_area_id;     String Area_name; Std::vector<area> Children;}   Read the data of a struct area from the area table according to the ID void id2findareatree (Session ses, area& area, int id) {Statement select (SES);  Select << "SELECT ID, parent_area_id,area_name from area where id =:p ID", Into (Area.id), into (area.parent_area_id), Into (Area.area_name), use (ID), now;}                Read tree data from the area table void Parent_id2findareatree (Session ses, std::vector<area>& varea, int parent_id) {    Varea.clear ();    typedef poco::tuple<long, long, string> area;    typedef std::vector<area> is;    is AR;    Statement Select (SES);     Select << "SELECT ID, parent_area_id,area_name from area where parent_area_id =:p id", to (AR), use (parent_id), now;    Are::const_iterator it = Ar.begin ();       for (; it! = Ar.end (); ++it) {area area;        Area.id = it->get<0> ();       area.parent_area_id = it->get<1> (); Area.area_name = it->get<2> ();    Varea.push_back (area); }}</span><pre name= "code" class= "CPP" ><span style= "FONT-SIZE:14PX;" >//build tree structure (entry function) session is a tool for connecting Oracle in Poco libraries void Cdlg::createtreectrl (session SES, long ID, area& area, Htreeitem H Item) {id2findareatree (SES, area, id); Htreeitem Hcurritem = M_tree. InsertItem (Area.area_name.c_str (), 0, 0, HItem, tvi_last);std::vector<area> temp; Parent_id2findareatree (SES, temp, id); Std::vector<area>::iterator it; for (it = Temp.begin (); It! = Temp.end (); it++) {Area A;  Createtreectrl (SES, it->id, A, hcurritem); if (!a.area_name.empty ()) {area.children.push_back (a);}}}     </span>//Finally, in the initialization function, call the entry function area Area;try {odbc::connector::registerconnector (); Session ses ("ODBC", "uid= user name;     pwd= password; database= database name; dsn= configured DSN ");     Createtreectrl (SES, 1, area, 0);   Odbc::connector::unregisterconnector (); } catch (Connectionfailedexception e) {}


Results such as:


Run, it's done! Feel useful friends, remember to praise Oh ~

C + + reads data from the database and displays the data on the Treectrl on the interface

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.