代码如下,作用是查询当日售票张数并对其加1,使之生成新的小票ID,当未查询到值或数据库无记录时结果便为1523752358(我估计这可能是SQL中整型字段为空引起的,我的quantity字段为整型);已查询到时一切正常,郁闷……为什么?
CTime t=CTime::GetCurrentTime();
CString m_txtID=t.Format("%Y%m%d%H%M");
CString m_NO;//CString strSQL="SELECT saletxtid=MAX(saletxtid) FROM saletxt WHERE saledate='";
CString strSQL="SELECT quantity=MAX(quantity) FROM inrecord WHERE indate='";
CString m_curdate;
m_curdate.Format("%4d-%02d-%02d",t.GetYear(),t.GetMonth(),t.GetDay());
strSQL+=m_curdate;
strSQL+="'";
try
{
theApp.m_pRecordset->Open((_bstr_t)strSQL,
theApp.m_pConn.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
if(!(theApp.m_pRecordset->adoEOF))
//m_NO.Format("%02d",theApp.m_pRecordset->GetCollect((_bstr_t)"saletxtid").intVal+1);
m_NO.Format("%02d",theApp.m_pRecordset->GetCollect((_bstr_t)"quantity").intVal+1);
else
m_NO="01";
}
catch(_com_error e)
{
CString strComError;
strComError.Format("查询记录失败!\r\n错误编号: %08lx\n错误信息: %s\n错误源: %s\n错误描述: %s",
e.Error(), // 错误编号
e.ErrorMessage(), // 错误信息
(LPCSTR) e.Source(), // 错误源
(LPCSTR) e.Description()); // 错误描述
::MessageBox(NULL,strComError,"错误",MB_ICONEXCLAMATION);
}
theApp.m_pRecordset->Close();
CTime t=CTime::GetCurrentTime();
CString m_txtID=t.Format("%Y%m%d%H%M");
CString m_NO;//CString strSQL="SELECT saletxtid=MAX(saletxtid) FROM saletxt WHERE saledate='";
CString strSQL="SELECT quantity=MAX(quantity) FROM inrecord WHERE indate='";
CString m_curdate;
m_curdate.Format("%4d-%02d-%02d",t.GetYear(),t.GetMonth(),t.GetDay());
strSQL+=m_curdate;
strSQL+="'";
try
{
theApp.m_pRecordset->Open((_bstr_t)strSQL,
theApp.m_pConn.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
if(!(theApp.m_pRecordset->adoEOF))
//m_NO.Format("%02d",theApp.m_pRecordset->GetCollect((_bstr_t)"saletxtid").intVal+1);
m_NO.Format("%02d",theApp.m_pRecordset->GetCollect((_bstr_t)"quantity").intVal+1);
else
m_NO="01";
}
catch(_com_error e)
{
CString strComError;
strComError.Format("查询记录失败!\r\n错误编号: %08lx\n错误信息: %s\n错误源: %s\n错误描述: %s",
e.Error(), // 错误编号
e.ErrorMessage(), // 错误信息
(LPCSTR) e.Source(), // 错误源
(LPCSTR) e.Description()); // 错误描述
::MessageBox(NULL,strComError,"错误",MB_ICONEXCLAMATION);
}
theApp.m_pRecordset->Close();
if ((theApp.m_pRecordset->adoEOF) && (theApp.m_pRecordset->BOF))