Thread: How to connect C++ to MS Access? Need advice. Please help.

  1. #1
    Registered User MarkSquall's Avatar
    Join Date
    Aug 2007
    Posts
    27

    Question How to connect C++ to MS Access? Need advice. Please help.

    Dear CProgramming administrators and members,

    Good day everyone. I hope everybody is in good health upon reading this thread. Well, like what the title of my thread says, may I ask if anyone could give me very basic instructions on how to connect my C++ code to MS Access file. Well, I just plan to enter an employee's name, employee's ID, his/her salary, and store those data in MS Access. Can someone recommend any website/s that I could follow step by step, pretty please?
    Well, just for additional information:

    1. I am using Code::Blocks
    2. I am using MS Access 2003
    3. My O.S. is Windows XP Service Pack 2


    I really don't know where to start. Should I download new "add-ons" to Code::Blocks? Should I make certian settings to Windows, etc. Well, I hope and pray someone could give me not codes, but tutorial/s (with explanations as possible) so that I could do and learn it on my own.

    Thank you very much for the time in reading this forum. God bless everyone.

    Respectfully yours,


    MarkSquall
    "Listen to advice and accept instruction, and in the end you will be wise." -Proverbs 19:20

  2. #2
    Not stupid, just stupider yaya's Avatar
    Join Date
    May 2007
    Location
    Earthland
    Posts
    204
    It depends on the filetype. From memory, you can save a MS Access file as a .mdb, but you can also export as many other things. The best one to work with is one that is very human-readable. A good example is XML. There are XML-reading libraries out there to make things easy, though I have no experience with them. That way you can import/export files that are also compatible with Access.

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    What? What depends on filetype???
    Anyhow, if you're trying to use Access, I might suggest ODBC. MFC has some helper classes for that. Otherwise, you could look for some source code to help you use ODBC. Check codeproject.com for example.
    And btw, I refuse to blessed by your "god." You may take it back.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Registered User MarkSquall's Avatar
    Join Date
    Aug 2007
    Posts
    27

    Talking Thanks for the Web site.

    Thank you for the Website http://www.codeproject.com, I will check it for articles and tutorials if ever.

    Can some one give me more referral websites about C++ (I'm doing a console program, hehehe) and MS Access database connection? The tutorial in http://www.codeproject.com are more Microsoft type, is there more like GNU C++? Anyway, I'll try it right away. Thank you in advance.


    Respectfully yours,

    MarkSquall
    "Listen to advice and accept instruction, and in the end you will be wise." -Proverbs 19:20

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    CodeProjects is a code snippets site. So it would contain many examples and tutorials, not just for Microsoft stuff.
    It was a long time ago I worked with Access from C++, though, and I used MFC, so äi don't have any specifically good resources. You're bound to find something on Google.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    I would say that since you insist on using MS (Microsoft) Access you are pretty much roping yourself into using a Microsoft solution. Yes you can use ODBC for it but apparently that has been suggested and discarded. GNU C++ is a very cross-platform solution and Access is not.
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    And your point is...?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    Quote Originally Posted by Elysia View Post
    And your point is...?
    My point is that:
    1. He/she is attempting to access a Microsoft database on a Microsoft OS *and*
    2. He/she has been offered two solutions (ODBC and MFC) *yet*
    3. He/she has discarded both solutions, one out of hand and the other due to being too "Microsoft"

    So his/her solution is to either accept the solutions offered OR go with something more cross-platform WRT the database (SQLite, MySQL, etc).

    Thought this would be obvious...
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

  9. #9
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Your post wasn't entirely clear, since there has been no mention of "disregarding" ODBC. The only information that was posted was "more Microsoft type", which can mean anything.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #10
    Registered User MarkSquall's Avatar
    Join Date
    Aug 2007
    Posts
    27

    Talking Microsoft is for Micrsoft I guess...

    To Sir jeffcobb:

    According to a mentor and a friend of mine, he is also recommending SQLite than using MSAccess. He said that if I'm using Microsoft Visual C++, then I should go for MSAccess, but if I'm in GNU C++(Code::Blocks), then he says better use SQLite. I'm just "required" to study how to use SQLite, hehehe....


    To be honest with everybody, I came up with this idea question because I've successfully connected a Java application in MSAccess (using JDBC---I know this is way too far easy with everybody else here, but I guess I'm just a plain old student here, so please don't laugh at me... ), then I wonder that if I've connected a Java application in MSAccess, I just wonder IF it is possible to use GNU C++ and MSAccess together, and like what Elysia said, I could find tutorials and codes from his/her recommended web site.

    Thanks everyone for the knowledge you gave, though I find it difficult to program database, I'm still willing to learn, And give it a shot (oooh yeah! hahaha). Thanks again.


    Respecfully yours,

    MarkSquall
    Last edited by MarkSquall; 02-17-2010 at 03:52 AM.
    "Listen to advice and accept instruction, and in the end you will be wise." -Proverbs 19:20

  11. #11
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Unlike Java, there is no standard API for doing this. So you have to rely on 3rd party.
    These examples may or may not be easy to use.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #12
    Registered User jeffcobb's Avatar
    Join Date
    Dec 2009
    Location
    Henderson, NV
    Posts
    875
    I guess it depends on what you intend to do:

    * If you are doing this to learn more about low-level database access in C or C++ then SQLite is not a bad way to go but it WILL require you to think like a database.
    * If you are doing this simply to learn more about interacting with a database at a higher level (read: SQL-only) then I would suggest something like MySQL; its bigger but easier to interact with at a higher level.
    * To me, the easier to use DB interfaces are in C++ (versus C) so I would reach for that first but if you are completely new to C and C++ and are only learning C (at the moment) then SQLite may be a better way to go since it is more C-like and SQLite is supported on all platforms you are likely to work on.

    In any event I would pull down sample code for SQLite and MySQL and see which makes more sense to you.
    C/C++ Environment: GNU CC/Emacs
    Make system: CMake
    Debuggers: Valgrind/GDB

  13. #13
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    I am using Code::Blocks
    This certainly does not work in your favor. If you want to connect to a Microsoft service, component, etc. then it would be wise to do it from a Microsoft compiler since they have been designed with this type of programming in mind. I'm not saying it's impossible from other compilers but it is sure to be a pain. Even the free express versions of MSVS should be able to do what you want.


    You may also be able to do this much easier from a .NET language like managed C++, C# or ...gasp.. VB.NET. It will certainly hide the nastiness from you. I really cannot in good faith recommend unmanaged C++ for this particular task.

    If MS Access has COM objects then you can certainly access them from any COM compatible language on a Win32 platform. If MS Access uses .NET...and I suspect they have been for some time then you should be able to access those as well from any .NET compatible language.

    If you absolutely must use unmanaged C++ then I understand as we often do not get to choose our various requirements but it will be a lot more involved than it probably should be.

    It should be as simple as being able to add an MS Access COM component to a form and then using it along with other MS Access COM components to do what you need. What I'm suggesting is the other side of the coin than what Salem suggested. What Salem suggested will connect you to the database itself and what I'm suggesting will connect you to the database via COM components designed to access and use the database and should hide all or most of the ODBC from you.
    Last edited by VirtualAce; 02-17-2010 at 10:40 PM.

  14. #14
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    Use SQLite or MySQL with C++, or MS Access with .NET (C# imo).
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. MS Exchange Calender access
    By maes in forum Windows Programming
    Replies: 2
    Last Post: 07-17-2004, 02:17 AM
  2. Ping
    By ZakkWylde969 in forum Tech Board
    Replies: 5
    Last Post: 09-23-2003, 12:28 PM
  3. The Timing is incorret
    By Drew in forum C++ Programming
    Replies: 5
    Last Post: 08-28-2003, 04:57 PM
  4. Question on MS Access
    By 041785h in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 10-08-2001, 09:18 AM
  5. Question on MS Access
    By 041785h in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 10-06-2001, 11:22 AM