picpath[j]是指针数组,存放图片的路径。
各位看一看问题出哪了 for (int j=0;j<=i;j++)
{
CFile file( picpath[j], CFile::modeRead); int nFileLen = file.GetLength();
if ( nFileLen<= 0 )
{
file.Close();
return;
}

BYTE* theFileContent = new BYTE[ nFileLen];
file.Read( theFileContent, nFileLen);
file.Close();

SAFEARRAY *psa; 
SAFEARRAYBOUND rgsabound[1]; 
rgsabound[0].lLbound = 0;
rgsabound[0].cElements = nFileLen;
psa = SafeArrayCreate( VT_UI1, 1, rgsabound);

void* theArrayBuffer = NULL;
::SafeArrayAccessData(psa, (void **)&theArrayBuffer); 
memcpy( theArrayBuffer, theFileContent, nFileLen);
::SafeArrayUnaccessData(psa); 

delete [] theFileContent;

VARIANT varChunk; 
varChunk.vt = VT_ARRAY|VT_UI1; 
varChunk.parray = psa; char s[2];
itoa(j,s,10);

CString s1="SELECT * FROM M_Pic where Id=" ;
CString strSQL = s1+ s; MessageBox(strSQL);

if ( m_pRecordset->GetState() )
 m_pRecordset->Close();

m_pRecordset->Open( (_variant_t)strSQL,variant_t((IDispatch*)m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
m_pRecordset->Fields->GetItem(_variant_t("Pic"))->Value=varChunk;
m_pRecordset->Update();

SafeArrayDestroy( psa);
free(picpath[j]);
}