Chapter 4. Show data of a column
Prev |  | Next

## Chapter 4. Show data of a column

Now we try to show data of a specific column. For this we get a hk_column object. hk_column represents a specific column of a datasource. To display the data of the actual row use the command mycolumn->asstring(). The hk_datasource::column_by_name method allows you to select a column by it's name.

When you enable a datasource the row selector is in row 0 (the first row). To move the row selector use one of the hk_datasource methods:

- bool goto_row (unsigned long r)

- bool goto_first (void)

- bool goto_last (void)

- bool goto_next (void)

- bool goto_previous (void)

Example 4.1. Show data of a column

    #define HAVE_SSTREAM 1
    #include <hk_classes.h>
    #include <iostream>
    int main()
    {
       hk_drivermanager* mydrivermanager = new hk_drivermanager();
       if (mydrivermanager==NULL) {cout <<"error creating mydrivermanager"<<endl;exit(1);}
       hk_connection* myconnection = mydrivermanager->new_connection("mysql");
       if (myconnection==NULL) {cout <<"error creating myconnection"<<endl;exit(1);}
       myconnection->set_host("localhost");
       myconnection->set_user("root");
       myconnection->set_password("mypasswd");
       myconnection->connect();

       hk_database* mydatabase=myconnection->new_database("exampledb");
       if (mydatabase==NULL) {cout <<"error creating mydatabase"<<endl;exit(1);}
       hk_datasource* mydatasource= mydatabase->new_table("authors");
       if (mydatasource==NULL) {cout <<"error creating mydatasource"<<endl;exit(1);}
       mydatasource->enable();

       hk_column* mycolumn = mydatasource->column_by_name("name");
       if (mycolumn==NULL) {cout <<"error getting column"<<endl;exit(1);}
       cout <<"Value of the first row: "<<mycolumn->asstring()<<endl;
       mydatasource->goto_next();
       cout <<"Value of the second row: "<<mycolumn->asstring()<<endl;

       delete mydrivermanager;
    }

Prev |  | Next
Chapter 3. Preselect the driver and user information | Home | Chapter 5. Alter data of a column