37,716
社区成员
发帖
与我相关
我的任务
分享
#-*- coding: utf-8 -*-
import win32com.client
from adoconstants import *
import time
DSN = r"Provider=KRTDBProvider.King.35;Persist Security Info=True;User ID=sa;Password=sa;Data Source=192.168.100.101"
Command = win32com.client.Dispatch(r"ADODB.Command")
Command.ActiveConnection = DSN
Command.CommandText = "SET @@SamplingMode = 'Stepped';SET @@SamplingInterval = 1000;SELECT TagName, DataTime, DataValue FROM History WHERE datatime BETWEEN '2018-10-1 00:00:01' AND '2018-10-1 3:00:00' AND TagName = 'name'"
#Command.CommandText = 'SELECT TagName, DataTime, DataValue FROM History WHERE datatime BETWEEN \'2018-10-1 00:00:01\' AND \'2018-10-1 3:00:00\' AND TagName = \'name\''
Command.CommandType = 8
Command.CommandTimeout = 0
Command.Prepared = True
(rs1,result) = Command.Execute()
while not rs1.EOF :
print(rs1.Fields.Item(1).Value)
rs1.MoveNext()
void COLEDBSampleDlg::OnBnClickedSearchdatabn()
{
HRESULT hr;
UpdateData(true);
CString strError;
if(m_SQLCommand==_T(""))
{
strError.Format (_T("SQL command string is empty!Please type "));
AfxMessageBox(strError);
return;
}
_variant_t vtEmpty;
VARIANT RecordsAffected;
try
{
pRecordset = pConnection->Execute((LPCTSTR)m_SQLCommand,
&vtEmpty, adCmdUnknown);
if(pRecordset==NULL)
{
strError.Format (_T("SQL Search Failed, check command "));
AfxMessageBox(strError);
return;
}
while( pRecordset!=NULL )
{
long countColumn=0;
hr=pRecordset->Fields->get_Count(&countColumn);
if( countColumn > 0 )
ShowData(pRecordset);
VariantInit( &RecordsAffected );
pRecordset = pRecordset->NextRecordset(&RecordsAffected);
VariantClear( &RecordsAffected );
}
if (pRecordset != NULL )
{
if (pRecordset->State == adStateOpen)
pRecordset->Close();
}
}