Opening Database with ADO Data Control

How do I open a database and a recordset in code using the ADO Data Control in Visual C++?


-Gregory Olds
gcoldsAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gcoldsAuthor Commented:
Thankyou for trying chensu, but that isn't my question.  I want to know how to use the ADO DataControl, not data bound controls.

-Gregory Olds
0
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

gcoldsAuthor Commented:
You can use the ADO Datacontrol independant of databinding.  In a couple of parts of my program, I access the contents of a recordset through code, not databinding.  I can manually access and manipulate data.  The only thing that I cannot figure out how to do is how to open a database using code instead of having a connectstring preset.

Gregory Olds
0
chensuCommented:
>You can use the ADO Datacontrol independant of databinding.

Yes, that is right. But a data bound control depends on a data source control.

>The only thing that I cannot figure out how to do is how to open a database using code instead of having a connectstring preset.

Check out the generated wrapper class. Call one of its member functions.
0
gcoldsAuthor Commented:
I've tried them but I ca'nt figure out how tto use them.

Gregory Olds
0
chensuCommented:
Have you checked out the help file Adodc98.chm?
0
gcoldsAuthor Commented:
It didn't help.  I wonder though if my problem isn't the fact that I'm trying to use the CAdodc in a generic non-mfc class?

-Greg
0
chensuCommented:
Do you mean that you are not using MFC? In order to host an ActiveX control, your window must be an ActiveX control container, which implements all the required interfaces. If you are not using MFC or ATL, you have to implement it yourself, which is not trivial.
0
gcoldsAuthor Commented:
The project itself is using mfc but not the specific class for which the CAdodc class is used in.  Is that why I'm having a problem?
0
chensuCommented:
How exactly are you creating the ActiveX control? What is the specific class? Do you call AfxEnableControlContainer in your application object's InitInstance function?
0
gcoldsAuthor Commented:
I just declared a generic class and in the private section of the class declaration I declared an ADO Data Control in it's definition.  Here's the declaration.

class DBMANAGER
{

      
private:
      CAdodc Database;
public:
      CString GetFieldVal(CString fname);
      void OpenRecordset(CString TableName);
      BOOL OpenDataSource();
};


I use this line of code to open the database in the function
OpenDataSource():

Database.SetConnectionString("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Sysfo.mdb;Mode=Read|Write|Share Deny None;Persist Security Info=False");


When I run the program, I get a debug assertion error in the file winocc.cpp in line 345.

What do you think?

Gregory Olds
0
gcoldsAuthor Commented:
I just declared a generic class and in the private section of the class declaration I declared an ADO Data Control in it's definition.  Here's the declaration.

class DBMANAGER
{

      
private:
      CAdodc Database;
public:
      CString GetFieldVal(CString fname);
      void OpenRecordset(CString TableName);
      BOOL OpenDataSource();
};


I use this line of code to open the database in the function
OpenDataSource():

Database.SetConnectionString("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Sysfo.mdb;Mode=Read|Write|Share Deny None;Persist Security Info=False");


When I run the program, I get a debug assertion error in the file winocc.cpp in line 345.

What do you think?

Gregory Olds
0
chensuCommented:
You should call the CAdodc::Create function first to create the ActiveX control. There should be a parent window to host it.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gcoldsAuthor Commented:
Your were right.  Thanks for all you help, you deserve these points.


Gregory Olds
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.