-
January 24th, 2018, 05:40 AM
#1
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!
-
January 24th, 2018, 05:54 AM
#2
Re: Retrieve data from sql server database
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++23 Compiler: Microsoft VS2022 (17.6.5)
-
January 24th, 2018, 07:21 AM
#3
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.
-
January 24th, 2018, 07:23 AM
#4
Re: Retrieve data from sql server database
Last edited by A_Singh; January 24th, 2018 at 07:24 AM.
Reason: Edited post.
-
January 24th, 2018, 07:49 AM
#5
Re: Retrieve data from sql server database
Originally Posted by A_Singh
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
-
January 24th, 2018, 08:07 AM
#6
Re: Retrieve data from sql server database
IAM using ODBC, well your solution works, any more inputs?
-
January 24th, 2018, 07:12 PM
#7
Re: Retrieve data from sql server database
Originally Posted by A_Singh
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?
-
January 25th, 2018, 10:51 AM
#8
Re: Retrieve data from sql server database
Originally Posted by Arjay
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.
-
January 25th, 2018, 09:30 PM
#9
Re: Retrieve data from sql server database
Well thank you, but sorry to say that cecordset and cdatabase are a part of ODBC only.
-
January 26th, 2018, 02:13 AM
#10
Re: Retrieve data from sql server database
Originally Posted by A_Singh
... sorry to say that cecordset and cdatabase are a part of ODBC only.
What do you mean?
Victor Nijegorodov
-
January 27th, 2018, 04:09 PM
#11
Re: Retrieve data from sql server database
Originally Posted by A_Singh
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|