本文共 1840 字,大约阅读时间需要 6 分钟。
2014年3月29日10:29:19
ADO查询站SQLServer,字段类型
_ConnectionPtr pStationConnection = NULL;//连接 _RecordsetPtr pStationRecordset = NULL;//记录集 pStationConnection.CreateInstance(__uuidof(Connection)); pStationRecordset.CreateInstance(__uuidof(Recordset)); //CString sInfo; try { _bstr_t strConnect =_T("Driver=SQL Server;Server=192.168.4.186,1433;Database=DBETC;UID=sa;PWD=123"); pStationConnection->Open(strConnect, _T(""),_T(""), adModeUnknown); sInfo.Format(_T("连接站库成功")); }catch (_com_error e) { sInfo.Format(_T("连接站库失败")); } DBG_AfxMessageBox(sInfo); StationExitRec aRec; //站SQL Server _bstr_t bstrSQL(_T("SELECT TOP 1 * FROM SEXIT2013090100007 WHERE ExitLane>1000 AND transfermark%16=0")); try { pStationRecordset->Open(bstrSQL, pStationConnection.GetInterfacePtr(), adOpenDynamic, adLockOptimistic, adCmdText); _variant_t var; int nSn = 0;int nSn1 = 0;int nSn2 = 0; CString str; CString str1; CString str2; if(!pStationRecordset->EndOfFile) { var = pStationRecordset->GetCollect(_T("ExitLane"));//smallint if((var.vt == VT_I2) || var.vt == VT_I4) { nSn = var.intVal; } var = pStationRecordset->GetCollect(_T("entryshift"));//tinyint if((var.vt == VT_I2) || var.vt == VT_I4) { nSn1 = var.intVal; } var = pStationRecordset->GetCollect(_T("recordno"));//int if((var.vt == VT_I2) || var.vt == VT_I4) { nSn2 = var.intVal; } var = pStationRecordset->GetCollect(_T("MVlicense"));//Varchar if(var.vt == VT_BSTR) { str1 = var.bstrVal; } var = pStationRecordset->GetCollect(_T("ProgramStartTime"));//datetime if(var.vt == VT_DATE) { str2 = COleDateTime(var).Format(); } str.Format(_T("SN:%d,str1:%s,str2:%s"),nSn,str1,str2); DBG_AfxMessageBox(str); } pStationRecordset->Close(); }catch (_com_error e) { exit(-1); }
转载地址:http://xjwci.baihongyu.com/