Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

access Table C++

Posted on 2008-06-13
9
Medium Priority
?
542 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
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 

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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

916 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