Home All Groups Group Topic Archive Search About

how to connect Access database

Author
2 Apr 2005 5:33 PM
AbdSol
I was using the following classes to get data from. Now I would like to know
which class shall I use from  Windows Forms VC++ 2005.

CDaoDatabase m_Dao;
             // Variables in  String Table
             // m_file = "C:\\Program Files\\Onair\\InVer.mdb"
             // m_upass = "password"
            m_Dao.Open(m_file ,FALSE, FALSE, m_upass);

CDaoRecordset m_Set;

COleVariant m_varprofile;
COleVariant m_varsection;

    m_Set.GetFieldValue ("Profile",  m_varprofile);

etc..,
Author
2 Apr 2005 6:51 PM
Val Mazur (MVP)
Hi,

You need to use ADO.NET that located in a System.Data namespace.
Specifically you need to use OLEDB .NET Managed provider . Check some
examples here

http://support.microsoft.com/default.aspx?scid=kb;en-us;310084

--
Val Mazur
Microsoft MVP

http://xport.mvps.org



Show quoteHide quote
"AbdSol" <Abd***@discussions.microsoft.com> wrote in message
news:4F83CAE3-C984-4472-9ADC-247FA2A0AB8E@microsoft.com...
> I was using the following classes to get data from. Now I would like to
> know
> which class shall I use from  Windows Forms VC++ 2005.
>
> CDaoDatabase m_Dao;
>             // Variables in  String Table
>             // m_file = "C:\\Program Files\\Onair\\InVer.mdb"
>             // m_upass = "password"
>            m_Dao.Open(m_file ,FALSE, FALSE, m_upass);
>
> CDaoRecordset m_Set;
>
> COleVariant m_varprofile;
> COleVariant m_varsection;
>
> m_Set.GetFieldValue ("Profile",  m_varprofile);
>
> etc..,
Are all your drivers up to date? click for free checkup

Author
4 Apr 2005 7:43 AM
AbdSol
I've read the msdn documents,  & the samples works but the sample is created
to prompt for the link.  When I modify the connection string as follows it
gives an error.

is it the right way or not...

IDataSourceLocatorPtr dlPrompt =
("Provider=Microsoft.Jet.OLEDB.4.0;Password=1234;User ID=Admin;Data
Source=Visu.mdb;");

& once connected do i have to use like this
_RecordsetPtr rs = NULL;



Show quoteHide quote
"Val Mazur (MVP)" wrote:

> Hi,
>
> You need to use ADO.NET that located in a System.Data namespace.
> Specifically you need to use OLEDB .NET Managed provider . Check some
> examples here
>
> http://support.microsoft.com/default.aspx?scid=kb;en-us;310084
>
> --
> Val Mazur
> Microsoft MVP
>
> http://xport.mvps.org
>
>
>
> "AbdSol" <Abd***@discussions.microsoft.com> wrote in message
> news:4F83CAE3-C984-4472-9ADC-247FA2A0AB8E@microsoft.com...
> > I was using the following classes to get data from. Now I would like to
> > know
> > which class shall I use from  Windows Forms VC++ 2005.
> >
> > CDaoDatabase m_Dao;
> >             // Variables in  String Table
> >             // m_file = "C:\\Program Files\\Onair\\InVer.mdb"
> >             // m_upass = "password"
> >            m_Dao.Open(m_file ,FALSE, FALSE, m_upass);
> >
> > CDaoRecordset m_Set;
> >
> > COleVariant m_varprofile;
> > COleVariant m_varsection;
> >
> > m_Set.GetFieldValue ("Profile",  m_varprofile);
> >
> > etc..,
>
>
>
Author
4 Apr 2005 12:31 PM
Paul Clement
On Mon, 4 Apr 2005 00:43:01 -0700, AbdSol <Abd***@discussions.microsoft.com> wrote:

¤ I've read the msdn documents,  & the samples works but the sample is created
¤ to prompt for the link.  When I modify the connection string as follows it
¤ gives an error.
¤
¤  is it the right way or not...
¤
¤ IDataSourceLocatorPtr dlPrompt =
¤ ("Provider=Microsoft.Jet.OLEDB.4.0;Password=1234;User ID=Admin;Data
¤ Source=Visu.mdb;");
¤
¤ & once connected do i have to use like this
¤ _RecordsetPtr rs = NULL;
¤

Could you identify the error and the line of code on which it occurs?


Paul
~~~~
Microsoft MVP (Visual Basic)
Author
4 Apr 2005 11:09 PM
AbdSol
the error code :-
error C2664: 'ado::Connection15::PutConnectionString' : cannot convert
parameter 1 from 'System::String __gc *' to '_bstr_t'

error line:-
conn->ConnectionString
=S"Provider=Microsoft.Jet.OLEDB.4.0;UserID=Admin;Password=1234;Data
Source=visu.mdb";

etc.,


this is how the code is Visual C++ .Net 2003
#include "stdafx.h"
#include <stdio.h>

#undef EOF
#import "c:\program files\common files\system\ole db\oledb32.dll"
rename_namespace("dlinks")
#import "c:\program files\common files\system\ado\msado15.dll"
rename_namespace("ado")

void TestConnection(void);

#ifdef _UNICODE
int wmain(void)
#else
int main(void)
#endif
{
    TestConnection();
    return 0;
}

void TestConnection(void)
{
    using namespace dlinks;
    using namespace ado;
    using namespace System;

    HRESULT hr;
       ::CoInitialize( NULL );

    IDataSourceLocatorPtr dlPrompt = NULL;
    hr = dlPrompt.CreateInstance(__uuidof(DataLinks));

    _ConnectionPtr conn = NULL;

    conn->ConnectionString
=S"Provider=Microsoft.Jet.OLEDB.4.0;UserID=Admin;Password=1235698;Data
Source=visu.mdb";


Show quoteHide quote
"Paul Clement" wrote:

> On Mon, 4 Apr 2005 00:43:01 -0700, AbdSol <Abd***@discussions.microsoft.com> wrote:
>
> ¤ I've read the msdn documents,  & the samples works but the sample is created
> ¤ to prompt for the link.  When I modify the connection string as follows it
> ¤ gives an error.
> ¤
> ¤  is it the right way or not...
> ¤
> ¤ IDataSourceLocatorPtr dlPrompt =
> ¤ ("Provider=Microsoft.Jet.OLEDB.4.0;Password=1234;User ID=Admin;Data
> ¤ Source=Visu.mdb;");
> ¤
> ¤ & once connected do i have to use like this
> ¤ _RecordsetPtr rs = NULL;
> ¤
>
> Could you identify the error and the line of code on which it occurs?
>
>
> Paul
> ~~~~
> Microsoft MVP (Visual Basic)
>
Author
5 Apr 2005 1:27 PM
Paul Clement
On Mon, 4 Apr 2005 16:09:02 -0700, AbdSol <Abd***@discussions.microsoft.com> wrote:

¤ the error code :-
¤ error C2664: 'ado::Connection15::PutConnectionString' : cannot convert
¤ parameter 1 from 'System::String __gc *' to '_bstr_t'
¤
¤ error line:-
¤ conn->ConnectionString
¤ =S"Provider=Microsoft.Jet.OLEDB.4.0;UserID=Admin;Password=1234;Data
¤ Source=visu.mdb";

The connection string looks OK, although you probably need to specify the System Database if you're
using user level security. Below is a connection string examples:

"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\somepath\mydb.mdb;Jet OLEDB:System
Database=system.mdw;User Id=admin;Password=;" 

You should be able to use the C++ OLEDB Data Provider example at:

http://support.microsoft.com/default.aspx?scid=kb;en-us;310071


Paul
~~~~
Microsoft MVP (Visual Basic)

Bookmark and Share