CString strSQL;
strSQL.Format(L"select 通话时刻,主叫号码 from  ak120.TAlarmCall;");//将CString对象设置为指定的字符串
int Ret;
Ret=m_dbi.DoOpen(strSQL.GetBuffer(0)) ; //GetBuffer就是返回当前这个CString类中的字符串头指针
printf("Ret=%d\n",Ret);
if(Ret!= 1)
{
printf("failed to select!\n");
} while (!m_dbi.Eof())
{
//
CString strBuf;
m_dbi.Field(L"主叫号码",strBuf);
printf("strBuf=%s\n",strBuf);
m_dbi.DoNext();
}INT CAdoDBI::DoOpen(CString strSQL)
{
try
{
if (ReConnect() != 0) //检查数据库连接是否断开,如果断开则重新连接
return -1;
//判断结果集指针是否还连接着别的结果集,连接着则断开
if (m_pRecordset->State != adStateClosed)
m_pRecordset->Close();
m_pCommand->ActiveConnection = m_pConnection; //设置连接指针
m_pCommand->CommandType = adCmdText; //设置串类型为SQL语句
//CString sSql=strSQL;
m_pCommand->CommandText = strSQL.GetBuffer();//.AllocSysString(); //设置SQL语句
m_pRecordset = m_pCommand->Execute(NULL,NULL,adCmdText);
// if(First()==0)
// return 0;
return m_pRecordset->RecordCount;
}
catch(_com_error &e) //COM异常
{
/* CString sError; //日志记录
sError.Format("执行返回结果集的数据库操作(%s)出错,",strSQL);
sError += "错误源:";
sError += e.Source();
sError += ",错误描述:";
sError += e.Description();
sError += "\n";
TRACE(sError);
*/
CString sError;
sError.Format(L"执行返回结果集的数据库操作(%s)出错,错误源:%s,错误描述:%s\n",strSQL,e.Source(),e.Description());
m_oLog.ErrorLog(sError,1);
return -1;
}
catch(...) //其他异常
{
CString sOther; //日志记录
sOther.Format(L"执行返回结果集的数据库操作(%s)异常。",strSQL);
TRACE(sOther);
m_oLog.ErrorLog(sOther,1);
return -1;
}
}