Solved

access Table C++

Posted on 2008-06-13
9
509 Views
Last Modified: 2013-12-05
My company uses a database that uses a fixed lenght dat file for its tables.  Me and another programmer who is not here anymore worked out a way to pull the data into access and also into msSQL.  this works out great, i know vba and sql pretty well so no problems.  every month, for billing porposes we have to update the parts costs in one of the tables.  The new parts cost are listed in another program that is updated and distributed to everyone that uses it month.  It uses propriety table structures and files and such but also had tools built into it for programmers to access the data through C++ and VB.  THis worked out great because we knew vb and was fast, we could update 53 thousand parts in about 5 minutes or so.  
Now though, the parts program is coded by another company and they have ripped out all vb compatibilty and only uses c++ which i barely knew 8 years ago.  now i know nothing.  I know you can integrate vb.net and c++.net but all of our program coding, which is extensive by now is done in access really.  we have a distributed adp which grants access to reports, table, querys and such.  

My question is, is there a way to get c++ to read an access table into an array or something.  once in the array i can loop through it and get the new parts cost using the tool provided.  i would rather not have to work on moving to vb.net out of our adp because we have been expanding/improving it for 4 years now and it is rather large.  I dont know vb.net and have started to learn it some but its just not clicking in my head yet.
0
Comment
Question by:talonsblade
  • 6
  • 2
9 Comments
 
LVL 86

Expert Comment

by:jkr
Comment Utility
Well, maybe http://www.codeproject.com/KB/database/readdb.aspx ("Using the CDatabase class to read an Access databases") can serve you as a starting point. This article demonstrates how to do what5 you described and comes with full source code.
0
 

Author Comment

by:talonsblade
Comment Utility
from reading that it looks like only the very beginning would be useful, the part about the recordset.  i did not know about recordsets in c++.  if i open the recordset from the access table, will any changes i make in the recordset be pushed back to the access table because that would be preferable.  i would like to keep the table in access because of all the processes we run with it
0
 
LVL 86

Expert Comment

by:jkr
Comment Utility
The changes will be reflected in the DB as soon as you call 'CRecordset::Update()' (http://msdn.microsoft.com/en-us/library/Aa312376.aspx). Maybe http://www.codeproject.com/KB/MFC/BeginnerDatabaseOpt.aspx ("Using Database in your MFC program - A beginner's experience") will help a bit more.
0
 

Author Comment

by:talonsblade
Comment Utility
this did not help much, like i said i dont know much about c++ and it kept giving me errors.  i did find the example in  this question
http://www.experts-exchange.com/Programming/Languages/C/Q_20136580.html
the example from AlexVirochovsky works perfectly but i cant figure out how to edit information in the recordset.  i changed the recordset to adopendynamic and adlockoptimistic but cant figure out how to change the data.
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

Author Comment

by:talonsblade
Comment Utility
here is a copy of  the code i am using
#import "c:\Program Files\Common Files\System\ADO\msado15.dll" \

no_namespace rename("EOF", "EndOfFile")

// This code comes from : www.geocities.

//     com/mokarrabin

#include <stdio.h>

#include <iostream.h>

void main(void)
 
 

    {

    CoInitialize(NULL);

    try 
 
 

        {

        _RecordsetPtr pRst("ADODB.Recordset");

        // Connection String

        _bstr_t strCnn("DRIVER={Microsoft Access Driver (*.mdb)};UID=admin;DBQ=GBOOK.mdb");

              // Open table

             pRst->Open("SELECT * FROM ProductService where ProductService like '%samir%';", strCnn, adOpenDynamic, adLockOptimistic, adCmdText);

              

              pRst->MoveFirst();
 
 

                  while (!pRst->EndOfFile) {

                       cout<<(char*) ((_bstr_t) pRst->GetFields()->GetItem("ProductService")->GetValue())<<endl;

                       pRst->MoveNext();

                  }

                  pRst->Close(); 

                  

        }

        catch (_com_error &e)
 
 

            {

            cout<<(char*) e.Description();

        }

        ::CoUninitialize();

    }

Open in new window

0
 

Author Comment

by:talonsblade
Comment Utility
jkr, could you please respond if you see this.  

like i said i have figured out how to change data in the recordset/table.  the websites i have read say that it is as easy as vb, which the begining isnt that much different until you get to output.  in vb you use recordset!field.  this example uses
(char*) ((_bstr_t) pRst->GetFields()->GetItem("ProductService")->GetValue())
ok i get pRst->GetFields()->GetItem("ProductService")->GetValue()), its kind of convoluted but its self explanitory.  ive done some searching on line and i know that _bstr_t is a function that takes the VB string, which i guess this recordset uses, and puts a c++ wrapper around it so its usable.

What i dont understand is why you have to take a pointer from it, i think that is what the (char*) is doing right?  Plus, how do i use this to update the fields.  would i have to convert it back to a bstr before?

Thanks for all your help jkr
0
 

Author Comment

by:talonsblade
Comment Utility
err the second line was supposed to say, i have NOT figured out how to change the data in the recorest/table
0
 
LVL 49

Expert Comment

by:DanRollins
Comment Utility
Just to be clear... do you need to update the Access Db, or do you just need the data to be in a memory array?
0
 

Accepted Solution

by:
talonsblade earned 0 total points
Comment Utility
I need to update the data ub the access db.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now