RE: C++ connection to OleDbConnection



Hi;

I finally figured out my problem.

You have to have two references in order for your declared object to
recognized.

Add them to your references folder in the solutions explorer.

They are:

System
System.Data

--
Gordon


"Gordon" wrote:

Hi;

Could someone point out my code error here.

When I try to compile I get a C2065 OleDbConnection undeclared identifier
error

msg.

Here is my code:


#using <mscorlib.dll>

#using <System.Data.dll>
using namespace System;
using namespace System::Data;
using namespace System::Data::OleDb;

#include "stdafx.h"


int _tmain(int argc, _TCHAR* argv[])
{

// The connection
//string cnNwind;

OleDbConnection * conn = new OleDbConnection();

conn->ConnectionString = S "Provider=Microsoft.Jet.OLEBD.4.0; "
S"Data Source=C:\my_databases\taxLots.mdb";


// The connection string

try
{
// Open Database
conn->Open();
Console::WriteLine(S"Connected to database successfully!");
}
catch (OleDbException * pe)
{
Console::Write(S"Error occurred: ");
Console::WriteLine(pe->Message);
}

// Close Connection
if (conn->State != ConnectionState::Closed)
{
conn->Close();
}
Console::WriteLine(S"The database connection is now closed");

return 0;
}

Thanks for any insights.


--
Gordon
.



Relevant Pages

  • C++ connection to OleDbConnection
    ... Could someone point out my code error here. ... When I try to compile I get a C2065 OleDbConnection undeclared identifier ... using namespace System; ... // The connection string ...
    (microsoft.public.data.oledb)
  • RE: Connecting an ADO.net database via C++.net
    ... You have to have two references in order for your declared object to ... Add them to your references folder in the solutions explorer. ... I am trying to use the OleDbConnection object. ... // The connection string ...
    (microsoft.public.dotnet.languages.vc)

Loading