Solved

STL list of microsoft ADODB recordsets

Posted on 2002-06-12
7
324 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
[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
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Quicksort a dynamic deque 33 79
thread-safe code in c++ 2 120
Microsoft C++ code failing in executable that worked 9 121
I could not set window to top 4 40
When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

740 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