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

  • Home
  • SEARCH
  • 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 6124683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:09:38+00:00 2026-05-23T16:09:38+00:00

I am trying to read a SQL Server table in C++ using a function

  • 0

I am trying to read a SQL Server table in C++ using a function like this..

CCommand<CDynamicAccessor>* Read(char* tblName)
    {
     wostringstream query;

     query << "SELECT * FROM " << tblName;

     return dataSource -> Query (query);
    }

which calls this other function

    CCommand<CDynamicAccessor>* Query(wostringstream& query)
    {

        HRESULT hr;
        hr = _cmd.Open(_sess, _T(query.str().c_str()));

        if (FAILED(hr))
           {
            std::wcout<<query.str().c_str() << "\n";
            THROW_EXCEPTION("Command not executed.");

           }
        return &_cmd;
        }

The problem is when I try to retrieve the column values using something like this

char* column20= (char*)cmd->GetValue("column20");

char* column21= (char*)cmd->GetValue("column21"); //Error

Because in the column20 I get the full string ex. “Value1”
But in the column21 I only get the first character ex. “V”, when I should get “Value2”

Is there any limitation in size or something like that which do not allow me to retrieve the full string for column21?

If so, what is the best way to solve this issue?

  • 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-23T16:09:38+00:00Added an answer on May 23, 2026 at 4:09 pm

    Most probably the result is a wchar_t * string and you cast it to char *

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to improve query readability by using a function in SQL Server
I'm trying to read data from SQL Server database using Perl and the DBI
I want to use CLR table-valued function in SQL Server 2008, which accesses a
In this live SQL Server 2008 (build 10.0.1600) database, there's an Events table, which
I am trying to select food_ItemName and food_UnitPrice from t_Food table in SQL Server
I'm trying to group table values by date, and this HQL query works fine:
I'm trying to change the size of a column in sql server using: ALTER
I am using SQL Server 2008R2 and one of the things I am trying
I am using a SqlDataReader and I am trying to read from a table
I'm trying to export from SQL Server to Oracle a table that consists of

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.