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
Solved

access Table C++

Posted on 2008-06-13
9
522 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
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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

860 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