Solved

access Table C++

Posted on 2008-06-13
9
525 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 2
9 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 21779990
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
ID: 21781139
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
ID: 21781339
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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

Author Comment

by:talonsblade
ID: 21825364
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
 

Author Comment

by:talonsblade
ID: 21826123
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
ID: 21846806
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
ID: 21846992
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
ID: 21882592
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
ID: 21898822
I need to update the data ub the access db.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
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.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

730 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