void CMainFrame::Request(char *buffer,SOCKET clientSock)
{
_ConnectionPtr Cnn;
_RecordsetPtr pRec; Cnn.CreateInstance(__uuidof(Connection));
pRec.CreateInstance(__uuidof(Recordset)); Cnn->Open("DSN=logbook","","",0);
pRec->Open("SELECT * FROM A", (IDispatch *)Cnn, adOpenDynamic, adLockOptimistic, adCmdText);
CString strDay((LPCSTR)buffer);
CString strLogContent((LPCSTR)buffer);
CString userName((LPCSTR)buffer);
_variant_t theValue;
char nowDay[8];
DtoStr(CTime::GetCurrentTime(), nowDay); userName.Delete(0,9);
userName.Delete(10, userName.GetLength()-10);
strDay.Delete(0,1);
strDay.Delete(8 , strDay.GetLength()-8); strLogContent.Delete(0,20);
//判定是否为当前日期
if (strDay==nowDay)
{
pRec->AddNew();
pRec->PutCollect("user",_variant_t(userName));
pRec->PutCollect("date",_variant_t(strDay));
pRec->PutCollect("logbook",_variant_t(strLogContent));
pRec->Update();
buffer="11";
send(clientSock,buffer,40,MSG_DONTROUTE);
Cnn->Close();
pRec->Close();
}
else if (strDay>nowDay)
//如果为以前的日期
{
BOOL flag=FALSE;
//判定是否存在日志,存在置flag为真
while (!pRec->adoEOF)
{
theValue=pRec->GetCollect("date");
if (strDay==(LPCSTR)(char *)_bstr_t(theValue))
{
flag=TRUE;
}
pRec->MoveNext();
}
if (!flag)
{
pRec->AddNew();
pRec->PutCollect("user",_variant_t(userName));
pRec->PutCollect("date",_variant_t(strDay));
pRec->PutCollect("logbook",_variant_t(strLogContent));
pRec->Update();
buffer="11";
send(clientSock,buffer,40,MSG_DONTROUTE);
}
}
pRec->Close();
}
{
_ConnectionPtr Cnn;
_RecordsetPtr pRec; Cnn.CreateInstance(__uuidof(Connection));
pRec.CreateInstance(__uuidof(Recordset)); Cnn->Open("DSN=logbook","","",0);
pRec->Open("SELECT * FROM A", (IDispatch *)Cnn, adOpenDynamic, adLockOptimistic, adCmdText);
CString strDay((LPCSTR)buffer);
CString strLogContent((LPCSTR)buffer);
CString userName((LPCSTR)buffer);
_variant_t theValue;
char nowDay[8];
DtoStr(CTime::GetCurrentTime(), nowDay); userName.Delete(0,9);
userName.Delete(10, userName.GetLength()-10);
strDay.Delete(0,1);
strDay.Delete(8 , strDay.GetLength()-8); strLogContent.Delete(0,20);
//判定是否为当前日期
if (strDay==nowDay)
{
pRec->AddNew();
pRec->PutCollect("user",_variant_t(userName));
pRec->PutCollect("date",_variant_t(strDay));
pRec->PutCollect("logbook",_variant_t(strLogContent));
pRec->Update();
buffer="11";
send(clientSock,buffer,40,MSG_DONTROUTE);
Cnn->Close();
pRec->Close();
}
else if (strDay>nowDay)
//如果为以前的日期
{
BOOL flag=FALSE;
//判定是否存在日志,存在置flag为真
while (!pRec->adoEOF)
{
theValue=pRec->GetCollect("date");
if (strDay==(LPCSTR)(char *)_bstr_t(theValue))
{
flag=TRUE;
}
pRec->MoveNext();
}
if (!flag)
{
pRec->AddNew();
pRec->PutCollect("user",_variant_t(userName));
pRec->PutCollect("date",_variant_t(strDay));
pRec->PutCollect("logbook",_variant_t(strLogContent));
pRec->Update();
buffer="11";
send(clientSock,buffer,40,MSG_DONTROUTE);
}
}
pRec->Close();
}
ado么! if( bAdd )//添加模式
{ unsigned char *pBuf = lpHead;
VARIANT varBLOB;
SAFEARRAY *psa;
SAFEARRAYBOUND rgsabound[1]; m_pRecordset->AddNew(); m_pRecordset->PutCollect("NUMBER",_variant_t(m_Number));
m_pRecordset->PutCollect("NAME",_variant_t(m_Name)); if(pBuf)
{
rgsabound[0].lLbound = 0;
rgsabound[0].cElements = lSize;
psa = SafeArrayCreate(VT_UI1, 1, rgsabound); for (long i = 0; i < (long)lSize; i++)
SafeArrayPutElement (psa, &i, pBuf++);
varBLOB.vt = VT_ARRAY | VT_UI1;
varBLOB.parray = psa;
m_pRecordset->GetFields()->GetItem("PHOTO")->AppendChunk(varBLOB);
} m_pRecordset->Update();
然后需要更新显示的列表,使它正确显示表里的内容!