views:

469

answers:

1

I have a native C++ DLL that uses COM ADO Recordsets and am in need of converting it to the .NET variant (ADODB::Recordset). I have tried several approaches to tackling this problem without success. The native C++ DLL dynamically creates and populates the COM Recordset. Ideally I'd do the same for the ADODB::Recordset within the managed wrapper, but the needed properties aren't accessible to me. For example, when attempting to utilize the Fields collection in order to Append Columns (despite intellisense telling me otherwise), I receive:

error C2039: 'Fields' : is not a member of 'ADODB::Recordset'

ADODB::Recordset ^RS = gcnew ADODB::Recordset ();
RS->Fields->Append("ID", DataTypeEnum::adInteger, 1, FieldAttributeEnum::adFldKeyColumn);

My C++/CLI solution contains the ADODB reference (c:\Program Files\Microsoft.NET\Primary Interop Assemblies\adodb.dll) version 7.0.3300.0 I am using Visual Studio 2005 with .NET Framework 2.0.50727 SP2

I would appreaciate it if someone in the StackOverflow community can direct me to a sample that dynamically populates a .NET ADO Recordset using C++/CLI.

A: 

I think that the main difference between the raw COM Recordset and the one provided by the .Net wrapper classes is just that some things get renamed. It is simply a wrapper around the underlying COM object and not a new class in its own right.

To answer your immediate example, try

RS->default->Append(...);

You could try to run ILDASM over the adodb.dll you have to see what the API on the recordset class is.

You can do the following too:

//Create instance of a recordset
ADODB::RecordsetClass^ recordset;
recordset = gcnew ADODB::RecordsetClass();

//Set some options
recordset->CursorLocation = ADODB::CursorLocationEnum::adUseClient ;
recordset->CursorType = ADODB::CursorTypeEnum::adOpenDynamic;
recordset->LockType = ADODB::LockTypeEnum::adLockBatchOptimistic;

//Add columns
recordset->default->Append("Name", ADODB::DataTypeEnum::adWChar, 50, ADODB::FieldAttributeEnum::adFldFixed, nullptr);
recordset->default->Append("Number", ADODB::DataTypeEnum::adWChar, 20, ADODB::FieldAttributeEnum::adFldFixed, nullptr);

//Build an array of field names
fields = gcnew array<Object^>(2);
fields[0] = gcnew String("Name");
fields[1] = gcnew String("Number");

//Add values
array<Object^>^ values = gcnew array<Object^>(2);
values [0] = "some name";
values [1] = 1.2;
recordset->AddNew(fields, values);

//Get a value out again
recordset->MoveFirst();
ADODB::Field^ pNum= recordset->default[1];
double num = Convert::ToDouble((pNum->default));
Colin Desmond

related questions