Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ database
i have worked on c++, but i never used database with c++. Can anyone can tell me how to do that. any link,sample code etc. will be appreciated.
Posted 6-Sep-12 9:34am
Comments
Wes Aday at 6-Sep-12 14:44pm
   
Based on your totally vague non-question http://www.bing.com/search?q=%22C%2B%2B%22+database&FORM=SAWRES&src=IE-SearchBox&adlt=strict
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

To add to what was said in Solution 1...
 
Install SQL Server on your local system. It should install as the SQLExpress version. This is a nearly full featured version of SQL Server. It's been tuned for personal use but supports most of the SQL Features and probably all of them that you would need. Be sure and install SQL Management Studio. You'll want that.
 
Create your console application with MFC support.
 
Use the class wizard to create your database classes/records from existing tables in the database.
 
Microsoft has announced that SQl Server OLE DB is being phased out in favor of ODBC. Avoid that unless you have a requirement to use it.
 
The CRecordSet based classes are easy to work with. You might start with those.
  Permalink  
Comments
footballpardeep at 7-Sep-12 12:42pm
   
thanks, I am trying
Mohibur Rashid at 7-Sep-12 18:29pm
   
yep, it would work
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

As wes Aday said, your question is vague. Why vague?
 

Well, you said you want to use c++. but what is missing?
I will say, your database. What database do you want to use? There is few popular database, but two common database I can recall
1. MySQL
2. postgresql.
 
Both of them are good with strong features. I suggested them because, both of them are free.
 
So, pick your database also pick your compiler. go to google.com and start searching with the name. You will get your way out............
  Permalink  
Comments
footballpardeep at 7-Sep-12 3:21am
   
Thanks for reply.
Let me explain one more time.
1)I want to develop a c++ console application( you can say employee record application, where user can save record to database, and can retrive it later.)
2) As i am familiar with microsoft sql server 2008, so i would like to prefer sql.
3) i searched on google or read some books but i don't found anything useful about using database with c++.
4)Any tutorial may be good or any sample.
Mohibur Rashid at 7-Sep-12 3:29am
   
Some people feel insulted when I tell them to start with google. I will also ask you, did you spend some time on google? not with stars name with "sql server 2008 c++ api" or anything else? I am not sure though. well, I searched for you, which I should not do, and found this link http://www.tidytutorials.com/2009/08/connecting-to-sql-server-using-c-odbc.html. I dont have special time for anyone. so you will have to search by yourself and there is lots of good example out there
footballpardeep at 7-Sep-12 3:41am
   
thanks, i will search and tell me one more thing, i am using Turbo c++ compiler, that will work for that or i will have to download some other compiler.
Mohibur Rashid at 7-Sep-12 6:34am
   
Probably version 3.0. No it wont work. Download express version of visual studio
JackDingler at 7-Sep-12 14:06pm
   
Right. It won't work. That compiler and it's libraries are very outdated.
footballpardeep at 7-Sep-12 12:42pm
   
I started working on it, but i am getting 10 errors:
Error 1 error C2664: 'SQLGetDiagRecW' : cannot convert parameter 4 from 'SQLCHAR [1024]' to 'SQLWCHAR *' c:\users\pardeep\documents\visual studio 2010\projects\consoleapp\consoleapp\page1.cpp 10 1 consoleApp
Error 2 error C2664: 'SQLDriverConnectW' : cannot convert parameter 3 from 'SQLCHAR *' to 'SQLWCHAR *' c:\users\pardeep\documents\visual studio 2010\projects\consoleapp\consoleapp\page1.cpp 38 1 consoleApp
Error 3 error C2664: 'SQLExecDirectW' : cannot convert parameter 2 from 'SQLCHAR *' to 'SQLWCHAR *' c:\users\pardeep\documents\visual studio 2010\projects\consoleapp\consoleapp\page1.cpp 53 1 consoleApp
Error 4 error C1083: Cannot open include file: '..\CommonDatabasePool.cpp': No such file or directory f:\installation files\vc\include\sqlsvrpool.h 11 1 consoleApp
Error 5 error C1083: Cannot open include file: 'pthread.h': No such file or directory c:\users\pardeep\downloads\compressed\cppdatabasepool\cppdatabasepool\crosshelper.h 13 1 consoleApp
6 IntelliSense: argument of type "SQLCHAR *" is incompatible with parameter of type "SQLWCHAR *" c:\users\pardeep\documents\visual studio 2010\projects\consoleapp\consoleapp\page1.cpp 10 60 consoleApp
7 IntelliSense: argument of type "SQLCHAR *" is incompatible with parameter of type "SQLWCHAR *" c:\users\pardeep\documents\visual studio 2010\projects\consoleapp\consoleapp\page1.cpp 10 76 consoleApp
8 IntelliSense: argument of type "SQLCHAR *" is incompatible with parameter of type "SQLWCHAR *" c:\users\pardeep\documents\visual studio 2010\projects\consoleapp\consoleapp\page1.cpp 33 17 consoleApp
9 IntelliSense: argument of type "SQLCHAR *" is incompatible with parameter of type "SQLWCHAR *" c:\users\pardeep\documents\visual studio 2010\projects\consoleapp\consoleapp\page1.cpp 35 17 consoleApp
10 IntelliSense: argument of type "SQLCHAR *" is incompatible with parameter of type "SQLWCHAR *" c:\users\pardeep\documents\visual studio 2010\projects\consoleapp\consoleapp\page1.cpp 53 55 consoleApp
JackDingler at 7-Sep-12 14:05pm
   
Your errors have to do with ANSI / Unicode issues...
 
But you're doing it the hard way. Use the CDatabase class to connect.
 
Use the class wizard to create CRecordset derived classes to access your database records.
 
This stuff is really simple if you let the tools do the work for you.
 
right click the project in the project pane and select and choose choose the MFC class option, then ODBC. Or whatever path is proper for the version of Visual Studio you are using.
Mohibur Rashid at 7-Sep-12 18:24pm
   
cdatabase is mfc based class, I think he started to learn only
Mohibur Rashid at 7-Sep-12 18:25pm
   
go to your project property(alt+F7) and change your character set to multibyte

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 DamithSL 295
1 OriginalGriff 285
2 Sergey Alexandrovich Kryukov 157
3 Afzaal Ahmad Zeeshan 154
4 Peter Leow 115
0 OriginalGriff 7,510
1 DamithSL 5,494
2 Sergey Alexandrovich Kryukov 4,954
3 Maciej Los 4,936
4 Kornfeld Eliyahu Peter 4,514


Advertise | Privacy | Mobile
Web02 | 2.8.141223.1 | Last Updated 7 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100