Solved

STL list of microsoft ADODB recordsets

Posted on 2002-06-12
7
319 Views
Last Modified: 2009-12-16
What i'm trying to do is, creating a linked list using the STL which contains recordsets.

Can you please send me a code sample of how to do it?

Here is what i have been trying to do on my main function:
     CoInitialize(NULL);
     {
      // TODO: Place code here.
     HRESULT hr = 0;
     _ConnectionPtr pCon;
     hr = pCon.CreateInstance("ADODB.Connection");
     hr = pCon->Open(L"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\\Program\\Database\\DB.mdb;Persist Security Info=False",L"",L"",0);
     
     _RecordsetPtr pRs;
     hr = pRs.CreateInstance("ADODB.Recordset");
     hr = pRs->put_CursorLocation(adUseClient);
     //hr = pRs->Open (L"select * from tblStatuses",_variant_t((IDispatch *) pCon, true),adOpenDynamic,adLockBatchOptimistic,0);
     hr = pRs->Open (L"select * from tbl",_variant_t(pCon.GetInterfacePtr(), true),adOpenDynamic,adLockBatchOptimistic,0);
     LISTRsPtrs lst;
     lst.insert(lst.end(),&pRs.GetInterfacePtr());
     }
     CoUninitialize();

AND IT DOESN'T WORK!
PLEASE HELP!! :-)

Thanks allot,

Asaf Lahav
0
Comment
Question by:asaflahv1
  • 3
  • 2
  • 2
7 Comments
 
LVL 22

Accepted Solution

by:
ambience earned 100 total points
ID: 7072441
What doesnt work ??
how are you declaring the list ?

>>     LISTRsPtrs lst;
    lst.insert(lst.end(),&pRs.GetInterfacePtr());

This goes out of scope immediately after the closing brace, maybe that is why ? by any chance do you have a global lst that you try to populate ?

As a side note using  

lst.push_back(..);

achieves the same.

post some details about what is not working and how are you delaring the lst or typedefing it.
0
 
LVL 22

Expert Comment

by:nietod
ID: 7072462
>>   lst.insert(lst.end(),&pRs.GetInterfacePtr());

shouldn't that be

   lst.insert(lst.end(),pRs->GetInterfacePtr());

A) pRs is a pointer, not an objcect, so you need -> instead of the . operator
B) you need to store pointers in this list, not pointers to pointers.
0
 
LVL 1

Author Comment

by:asaflahv1
ID: 7077016
Eventually i succeeded storing a list of recordsets.
Unfortunately it wasn't any of the suggestions you supplied to make it work.

the problem was that i defined a list that was declared of _RecordsetPtr template.
And i guess the smart pointer had a problem with that.
So I simply changed the declaration and it all works.

Thanks allot for the effort anyway,

Asaf Lahav.

p.s, i'm going to give the points to ambience because his answer was the closest.

Thanks allot,
C'ya later aligator
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 22

Expert Comment

by:nietod
ID: 7077050
You should realize that the reason that none of the answers were good was that we needed more information.  We asked you questions and never got any answers.   We just didn't know enough about your list and other aspects of the code to understand the problem.  I'm glad you got a solution, but it might have been faster and easier for you if you had responded.

I should also add that providing ambience with a "C" is a bit harsh.   She (I think it is "she", right?) is a good expert and probably has at least a B, if not A, average.   To give her a C for circumstances beyone her control (insufficient information) is a bit unfair  Many experts would prefer to receive no grade, rather than a bad grade..
0
 
LVL 22

Expert Comment

by:ambience
ID: 7077194
>> She (I think it is "she", right?)

Now that i think is a direct assault on my sexual identity ... hey!

OK here, http://www.experts-exchange.com/cplusprog/Q.20304017.html, you can find out whether am a he or a he !!

>> Many experts would prefer to receive no grade, rather than a bad grade..

Though am not a die hard for points but this is Absolutely Absolutely true, and has come right from the core of my heart !!!!

I think there should be an option of "No Thank You!" to address such situations, boy i would love that. Is this in the agenda ?????????

I certainly cannot understand why "COMMENTS" are awarded C grade, a proposed answer getting a C or a B is understandable (maybe) but a comment ??. its just a comment not a "request for points", and if someones not satisfied then he/she can say so or can ask for more information.

I really hate this practice but theres nothing that i can do.

>> Unfortunately it wasn't any of the suggestions you supplied to make it work.

You could've asked for deletion of this question !
0
 
LVL 22

Expert Comment

by:nietod
ID: 7077855
>>  think there should be an option of "No Thank You!" to address such
>> situations, boy i would love that. Is this in the agenda ?????????
Not as easy, but you can post a request in the customer service topic area to have them delete this or maybe up the grade.
0
 
LVL 1

Author Comment

by:asaflahv1
ID: 7077862
ambience and nietod,

I'm truely sorry.

I never ment to hurt anyones feelings...
I honnestly and truely appreciate the effort you all made to help me with my dillema.

I simply succeeded in solving this before any affective advice was given...
So i thought it would be better to atleast award one of you guys for the effort and thought you would be glad to receive those points...

Anyhow, I apologize people...

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

840 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