標(biāo)題: ACCESS按時(shí)間段等組合條件查詢數(shù)據(jù) [打印本頁(yè)]

作者: bibi    時(shí)間: 2015-4-18 20:58
標(biāo)題: ACCESS按時(shí)間段等組合條件查詢數(shù)據(jù)
這個(gè)整了很多麻煩的事情。。。記號(hào),
void CSyslogDlg::FindLog()
{
CTime dtStartDate,dtStartTime;
CTime dtEndDate,dtEndTime;
m_date1.GetTime(dtStartDate);
m_time1.GetTime(dtStartTime);
m_date2.GetTime(dtEndDate);
m_time2.GetTime(dtEndTime);

CString strUser;
int nIndex = m_ctrlUser.GetCurSel();
if (CB_ERR != nIndex)
m_ctrlUser.GetLBText(nIndex,strUser);
if(strUser.IsEmpty()) return;

ADOConn m_AdoConn;
m_AdoConn.OnInitADOConn();

CString sql;
sql.Format(_T("SELECT tbrz.sj,tbrz.czy,tbrz.nr FROM tbrz where czy='%s' and sj between CDate('%s %s') and CDate('%s %s')"),
strUser,
dtStartDate.Format(_T("%x")), dtStartTime.Format(_T("%X")),
dtEndDate.Format(_T("%x")), dtEndTime.Format(_T("%X")));

TRACE(sql);
int i = 0;
_RecordsetPtr pRecordset;
pRecordset = m_AdoConn.GetRecordset((_bstr_t)sql);
m_wndList.DeleteAllItems();
while (!pRecordset->adoEOF)
{
  CString str;
  str.Format(_T("%d"), i);
  m_wndList.InsertItem(i, str);
  
m_wndList.SetItemText(i,1,(TCHAR *)(_bstr_t)pRecordset->GetCollect("czy"));
  m_wndList.SetItemText(i,2,(TCHAR *)(_bstr_t)pRecordset->GetCollect("sj"));
  m_wndList.SetItemText(i,3,(TCHAR *)(_bstr_t)pRecordset->GetCollect("nr"));

pRecordset->MoveNext();
i++;
}

m_AdoConn.ExitConnect();
}


















歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1