Array of Objects?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

When looking at the RecordsetClass in the ADODB primary interop assembly, the
AddNew method has the following signature

ADODB::RecordsetClass::AddNew([System::Object], [System::Object])

The text suggests that both parameters are arrays of objects, but it doesn't
accept an array<Object^>^. Is there any other way of getting this to work?

Thanks

Colin
 
the following works for me:

ADODB::RecordsetClass ^ test = gcnew RecordsetClass();
array<Std::String ^> ^ fields = {"fieldName"};
array<Std::String ^> ^ values = {"Value"};
test->AddNew(fields, values);

the AddNew method throws an exception because i have not opened a connection
(don't know plain ADO that well), but there is no problem with passing the
arrays.

kind regards,
Bruno.
 
Thanks for that Bruno,

Unfortunately it doesn't work for me. Here is my code

RecordsetClass^ rs = gcnew RecordsetClass();
rs->CursorLocation = ADODB::CursorLocationEnum::adUseClient ;
rs->CursorType = ADODB::CursorTypeEnum::adOpenStatic;
rs->LockType = ADODB::LockTypeEnum::adLockBatchOptimistic;

rs->default->Append("Column 1", ADODB::DataTypeEnum::adVarChar, 60,
ADODB::FieldAttributeEnum::adFldFixed, nullptr);
rs->default->Append("Column 2", ADODB::DataTypeEnum::adVarChar, 60,
ADODB::FieldAttributeEnum::adFldFixed, nullptr);
rs->default->Append("Column 3", ADODB::DataTypeEnum::adVarChar, 60,
ADODB::FieldAttributeEnum::adFldFixed, nullptr);


rs->Open(Type::Missing, Type::Missing, ADODB::CursorTypeEnum::adOpenStatic,
ADODB::LockTypeEnum::adLockBatchOptimistic, -1);

array<String ^> ^ fields = {"Column 1"};
array<String ^> ^ values = {"Value 1"};

rs->AddNew(fields, values);

The AddNew throws the following exception

"Item cannot be found in the collection corresponding to the requested name
or ordinal."

The only difference I can see between your code and mine is you use
Std::String and I used System::String, I can't get Std::String to compile!

Any thoughts?

Colin
 
now that i could have a look at your code, the first thing that comes to mind
is that your record set contains 3 columns, but when you add a new row, you
only supply a value or 'Column 1'.

have you tried supplying values for all 3 fields? the exception message
seems to indicate that this is your problem.

i don't know why i used Std::String instead of System::String. I used
std::string a lot in native C++. i guess it was an sub concious typo :)

kind regards,
Bruno.
 
Bruno,

I have tried

array<String ^> ^ fields = {"Column 1", "Column 2", "Column 3"};
array<String ^> ^ values = {"Value 1","Value 2","Value 3"};

then

rs->AddNew(fields, values);

but it still throws the same exception.

Colin
 
Back
Top