Advertisement

07.13.2004 at 11:12AM PDT, ID: 21057356
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.6

database access using ADO

Asked by papaflo in Windows MFC Programming

Tags: ,

DanRollins gave me this nice, console-based,  piece of code (see below) that basically returns values taken from a database

it basically opens up a connection to the database using ADO and populates a recordset using a select sql statement

questions:
1. how do i modify this to do inserts or updates (sql statements) without opening up a recordset?
i guess i'm looking for the c++ sytax of the following vb code
connection.Execute "insert into table (...) values (...)", , adCmdText Or adExecuteNoRecords
i know i can just replace the select statement with an insert statement and not loop thru the recordset but i'd like to not open up a recordset while executing an insert statement, if that's possible

2. what does "vtMissing" and " -1" mean in
spRS->Open("select au_lname, au_fname from authors", vtMissing, adOpenKeyset, adLockBatchOptimistic, -1);
any of you know where i can grab a nice documentation of all these

3. the code works fine but why do i get a linking error that reads:
LINK : warning LNK4098: defaultlib "LIBCMT" conflicts with use of other libs; use /NODEFAULTLIB:library
how do i eliminate this error?

4. i'm also looking for the c++ equivalent of the following vb code
Set cm = New ADODB.Command
cm.CommandText = "TrafficOnlyCheck"
cm.CommandType = adCmdStoredProc
cm.Parameters.Append cm.CreateParameter("@PackageId", adInteger, adParamInput, , CLng(strPackageId))
cm.Parameters.Append cm.CreateParameter("@CanTraffic", adInteger, adParamOutput)
Set cm.ActiveConnection = connection
cm.Execute
blnCanTraffic = cm.Parameters("@CanTraffic")
Set cm = Nothing

thanks,

f


DanRollins code:
#include <stdio.h>
#include <afxdisp.h>

#import "c:\program files\common files\system\ado\msado15.dll" rename ("EOF","adoEOF") no_namespace

#define CREATEiNSTANCE(sp,riid) { HRESULT _hr =sp .CreateInstance( __uuidof( riid ) ); \
                                  if (FAILED(_hr)) _com_issue_error(_hr); }

#define RsITEM(rs,x) rs->Fields->Item[_variant_t(x)]->Value
#define UC (char *)
struct InitOle {
    InitOle()  { ::CoInitialize(NULL); }
    ~InitOle() { ::CoUninitialize();   }
} _init_InitOle_;       // Global Instance to force load/unload of OLE

void main(){

    _RecordsetPtr   spRS;
    _ConnectionPtr  spCON;
    try{
        CREATEiNSTANCE(spCON,Connection);
        spCON->ConnectionString = L"driver={sql server};SERVER=(local);Database=pubs;"
                                  L"UID=sa; PWD=;";
         spCON->ConnectionString =L"DRIVER={Microsoft Access Driver (*.mdb)};"
                                     L"DBQ=authors.MDB;DefaultDir=C:\\test;";
             
        spCON->Open( "", "", "", -1 );
        CREATEiNSTANCE(spRS,Recordset)
        spRS->PutRefActiveConnection( spCON );
        spRS->Open("select au_lname, au_fname from authors", vtMissing, adOpenKeyset,
                    adLockBatchOptimistic, -1);
       
        while(spRS->adoEOF == false){
            printf("au_lname = %s  au_fname = %s \n", UC _bstr_t(RsITEM(spRS,0L)),
                                                 UC _bstr_t(RsITEM(spRS,"au_fname")));
            spRS->MoveNext();
        }
        spRS->Close();
        spCON->Close();
       
    }
    catch( _com_error &e){
        _bstr_t bstrSource(e.Source());
        _bstr_t bs =  _bstr_t(" Error: ") + _bstr_t(e.Error()) + _bstr_t(" Msg: ")
            + _bstr_t(e.ErrorMessage()) + _bstr_t(" Description: ")
            + _bstr_t(e.Description());
       
        MessageBox(0,bs,bstrSource, MB_OK);
    }          
}
#undef UCStart Free Trial
 
Loading Advertisement...
 
[+][-]07.13.2004 at 11:52PM PDT, ID: 11546328

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.14.2004 at 12:14AM PDT, ID: 11546416

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.14.2004 at 05:16AM PDT, ID: 11548078

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.14.2004 at 11:57AM PDT, ID: 11552408

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.14.2004 at 12:49PM PDT, ID: 11553009

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]07.15.2004 at 08:35AM PDT, ID: 11560047

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.24.2004 at 02:55PM PDT, ID: 11629742

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Windows MFC Programming
Tags: access, ado
Sign Up Now!
Solution Provided By: Fadi_Hania
Participating Experts: 5
Solution Grade: A
 
 
[+][-]07.26.2004 at 06:04AM PDT, ID: 11636852

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-44