Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5965245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:34:37+00:00 2026-05-22T19:34:37+00:00

How to read a table from SQL Server 2008 to a a vector in

  • 0

How to read a table from SQL Server 2008 to a a vector in C++ in the following way:

SQL TABLE 2008 table

1att 2att 3att 4att 5att 6att 7att ... attn
--------------------------------------------
565  526  472  527  483  529  476  470  502
497  491  483  488  488  483  496  515  491
467  516  480  477  494  497  478  519  471
488  466  547  498  477  466  475  480  516

Take every odd column into a only vector…

 array[565, 497, 467, 488,  //1att column 
       472, 483, 480, 547,  //3att column
       483, 488, 494, 477,  //5att column
       ...
       502, 491, 471, 516,  //Last odd att column
       ]

I am using:

#include <vector>
size_t size = 10;                //HOW TO GET THE SIZE
std::vector<int> array(size);    // make room for ,
                                 // and initialize them to 0

for(int i=0; i<size; ++i){
    array[i] = i;
}
...

So my main problem is how to communicate c++ with SQL, and then read the table into the vector… I am using Visual Studio 2008

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T19:34:38+00:00Added an answer on May 22, 2026 at 7:34 pm

    There are many ways to do this:

    1. Fetching single columns from
      database
    2. Fetching odd columns from database
    3. Fetching entire table from database

    Fetching Single Columns

    In this method, you tell the data base to select one column. You fill in a single vector by iterating through the result set. Repeat for each column you are interested in, using different vectors for each column.

    Fetching odd columns from database

    Tell database to return all the columns you are interested in (use many columns in the SELECT statement). Read a record from the result set. Put append values from the fields into appropriate vectors. Repeat reading & extraction for each record in the result set.

    Fetching entire table from database.

    Similar to above. Tell database to fetch all columns. While there is a result set record, copy values from interested fields into appropriate vectors.

    The latter method may be fastest since the database is returning rows from the table without filtering. The other methods require the database to create a new result set of records, filtering from the existing table. The fastest algorithm is obtained by profiling.

    Edit 1: Sample Code

    I don’t use SQL Server 2008, but MySQL. So this code will not work exactly for your purposes.

    const char * select_statement[] =
    "SELECT 1att, 3att, 5att, 7att, 9att\n"
    "FROM data_table;\n";
    
    Result_Set_Type * p_result_set = 0;
    p_result_set = database.execute_query(select_statement);
    if (p_result_set)
    {
        while (p_result_set->next())
        {
            att1_vector.push_back(p_result_set->get_value("1att");
            att3_vector.push_back(p_result_set->get_value("3att");
            att5_vector.push_back(p_result_set->get_value("5att");
            att7_vector.push_back(p_result_set->get_value("7att");
            att9_vector.push_back(p_result_set->get_value("9att");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have many .NET processes reading messages from an SQL Server 2008 DB table
I've a large (1TB) table in SQL Server 2008 that looks something like this:
I have a simple table in my SQL Server 2008 DB: Tasks_Table -id -task_complete
I created a C#.net app that uses dates from a SQL Server 2008 database
I'm having a problem with deadlock on SELECT/UPDATE on SQL Server 2008. I read
I am trying to select food_ItemName and food_UnitPrice from t_Food table in SQL Server
How i can read this line from csv in sql server ad,aixas,Aixàs,06,42.4833333,1.466666 when i
I am trying to select food_ItemName and food_UnitPrice from t_Food table in SQL Server
SQL Server 2008: I've got a situation here in which I wish to read
I am using SQL Server 2008 Enterprise. I have yearly customer data from 2000

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.