Yes, conversion is required. The _variant_t
class is not a very happy match, for an unfathomable reason it is missing a constructor that take a BSTR, the one that takes a _bstr_t
is unattractive because it copies the string. Fall back to the native VARIANT type, like this:
using namespace System::Runtime::InteropServices;
...
String^ s = Library::IdGenerator->GenerateNewId();
VARIANT v = { VT_BSTR };
v.bstrVal = (BSTR)Marshal::StringToBSTR(s).ToPointer();
recordset->Fields->GetItem(L"Id")->Value = v;