dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Mar 2017
    Posts
    105

    Retrieve data from sql server database

    I use Microsoft sql server 2014. What I want to do is, to get data from a particular column in my database and store it in a variable. I use SQL and c++ languages, so please give answer according to these. Thanks for any answer!

  2. #2
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,218

    Re: Retrieve data from sql server database

    You don't say your level of knowledge/experience of sql/c++. Does the c++ code already connect to the sql database etc? Consider

    https://www.codeproject.com/Question...-Cplus-Program
    https://www.codeproject.com/Question...to-a-MS-SQL-DB
    https://docs.microsoft.com/en-us/vis...-tools-for-cpp
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++17 Compiler: Microsoft VS2017 (15.7.2)

  3. #3
    Join Date
    Mar 2017
    Posts
    105

    Re: Retrieve data from sql server database

    Thanks for your kind help. Sorry to say that I know how to connect to a database, and my code does that, I just want the answer to my probelem.

  4. #4
    Join Date
    Mar 2017
    Posts
    105

    Re: Retrieve data from sql server database

    Quote Originally Posted by 2kaud View Post
    You don't say your level of knowledge/experience of sql/c++. Does the c++ code already connect to the sql database etc? Consider

    https://www.codeproject.com/Question...-Cplus-Program
    https://www.codeproject.com/Question...to-a-MS-SQL-DB
    https://docs.microsoft.com/en-us/vis...-tools-for-cpp
    Well I am experienced in sql and c++.:
    Last edited by A_Singh; January 24th, 2018 at 06:24 AM. Reason: Edited post.

  5. #5
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,144

    Re: Retrieve data from sql server database

    Quote Originally Posted by A_Singh View Post
    Thanks for your kind help. Sorry to say that I know how to connect to a database, and my code does that, I just want the answer to my probelem.
    So what means are you using to connect: ODBC, ADO, something else?
    In any case you would do something like open a recordset with a SELECT query, then read the needed field from a recordset to your variable.
    Victor Nijegorodov

  6. #6
    Join Date
    Mar 2017
    Posts
    105

    Re: Retrieve data from sql server database

    IAM using ODBC, well your solution works, any more inputs?

  7. #7
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    12,656

    Re: Retrieve data from sql server database

    Quote Originally Posted by A_Singh View Post
    IAM using ODBC, well your solution works, any more inputs?
    Why use ODBC to connect to MS SQL? For database work it's like the equivalent of working with strings but not using a string class. Sure you can do it, but why spend time reinventing the wheel?

  8. #8
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,518

    Re: Retrieve data from sql server database

    Quote Originally Posted by Arjay View Post
    Why use ODBC to connect to MS SQL? For database work it's like the equivalent of working with strings but not using a string class. Sure you can do it, but why spend time reinventing the wheel?
    Using a CRecordset derived class is about as easy as it gets.

  9. #9
    Join Date
    Mar 2017
    Posts
    105

    Re: Retrieve data from sql server database

    Well thank you, but sorry to say that cecordset and cdatabase are a part of ODBC only.

  10. #10
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,144

    Re: Retrieve data from sql server database

    Quote Originally Posted by A_Singh View Post
    ... sorry to say that cecordset and cdatabase are a part of ODBC only.
    What do you mean?
    Victor Nijegorodov

  11. #11
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    12,656

    Re: Retrieve data from sql server database

    Quote Originally Posted by A_Singh View Post
    Well thank you, but sorry to say that cecordset and cdatabase are a part of ODBC only.
    CRecordset and CDatabase are part of MFC which has nothing at all to do with ODBC.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)


×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.