Hey guys, I'm having a problem with ADO using C++, can anyone help?
The code is as follows: _CommandPtr cmd;
cmd.CreateInstance(__uuidof(Command));
cmd->ActiveConnection = con; // con is the connection set up earlier
cmd->CommandType = adCmdText;
cmd->CommandText = "declare @sys_key varchar(10) set @sys_key=? select top 1 [sys_key], [value], [description] from system_directory order by sys_key";
cmd->Parameters->Append(
cmd->CreateParameter(
"@sys_key",
adVarChar,
adParamInput,
10,
NULL
)
);
_variant_t var = "BM_PRINT";
cmd->Parameters->Item[0]->Value = var; // FAIL!
rec = cmd->Execute(NULL, NULL, -1);
But the line marked as FAIL, which is supposed to set the first (and in this case only) parameter to "BM_PRINT" throws an exception with error 0x800a0cc1, "Item cannot be found in the collection corresponding to the requested name or ordinal."
This doesn't make sense to me as I just created the parameter. Any ideas what's going on??
Name:
Anonymous2006-10-04 12:12
Note that the corresponding VBA code works fine:
Dim con As New Connection
With con
.ConnectionString = "Provider=SQLOLEDB;Network Library=DBMSSOCN;Data Source=PFW-TEST;Database=DEVEL;Integrated Security=SSPI"
.Open
End With
Dim cmd As New Command
With cmd
Set .ActiveConnection = con
.CommandType = adCmdText
.CommandText = "declare @sys_key varchar(10) set @sys_key=? select top 1 [sys_key], [value], [description] from system_directory order by sys_key"
.Parameters.Append cmd.CreateParameter("@sys_key", adVarChar, adParamInput, 10, Null)
v = "BM_PRINT"
.Parameters.Item(0).Value = v
.Execute
End With
Name:
Anonymous2006-10-04 15:15
WAT R U DOIN
Name:
Anonymous2006-10-04 15:56
What is ADO? Yet another Microsoft acronym for some useless proprietary "innovation"?