How to access varbinary field



hi all

The following is my code that access varbinary field(in SQL Server 2000) but
failed always

unsigned long data[3] = {101, 301, 505}; // for test
TCHAR *sql = _T("update A set F2 = @data where F1 = 1000");

pCmd->CommandText = sql;
pCmd->CommandType = adCmdText;
pCmd->CommandTimeout = 0;

_variant_t var;

// Create a SAFEARRAY.
SAFEARRAY *psa = SafeArrayCreateVector(VT_UI1, 0, sizeof(data));

// Copy the data to the SAFEARRAY.
int *pData;
HRESULT hr = SafeArrayAccessData(psa, (void **)&pData);
memcpy(pData, data, sizeof(data));
SafeArrayUnaccessData(psa);

//Assign the Safe array to a variant.
var.vt = VT_ARRAY|VT_UI1;
var.parray = psa;

_ParameterPtr param = pCmd->CreateParameter(_T("@data"), adVarBinary,
adParamInput, sizeof(data), var);
pCmd->Parameters->Append(param);

pCmd->Execute(NULL, NULL, adCmdText);

SafeArrayDestroy(psa);

Any hint?

TIA

sky


.



Relevant Pages

  • Visual FoxPro OLE DB Provider error 0x80040e46 (Unknown)
    ... SAFEARRAY * psaFields; ... SAFEARRAY * psaValues; ... var = ResourceW.AllocSysString; ...
    (microsoft.public.data.oledb)
  • Re: client side add to a table
    ... 'Write to SQL Server. ... > "Ken Dopierala Jr." ... >> Hi Mark, ... >> var tblMyTable = document.getElementById; ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Removing deadlock
    ... I support the Professional Association of SQL Server and it's community of SQL Server professionals. ... > Could MS SQL Server be setup to have no deadlock in this code (insert in> transaction from one connection and select from another without closing ... > var conn1 = new ActiveXObject;> var conn2 = new ActiveXObject; ... > cmd.ActiveConnection = conn1; ...
    (microsoft.public.sqlserver.programming)
  • Re: UPDATE and SELECT in one statement
    ... I'm a bit brainwashed by the SQL Server Programming dialect... ... Oracle 9i Personnal Edition. ... var bnd1 NUMBER ... var bnd2 VARCHAR2 ...
    (comp.databases.oracle.server)
  • Re: Removing deadlock
    ... Wayne Snyder, MCDBA, SQL Server MVP ... > Could MS SQL Server be setup to have no deadlock in this code (insert in ... > var conn1 = new ActiveXObject; ...
    (microsoft.public.sqlserver.programming)