ADO查询站SQLServer,字段类型

来源:互联网 发布:js date 初始化 编辑:程序博客网 时间:2024/04/30 06:03

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"));//smallintif((var.vt == VT_I2) || var.vt == VT_I4){nSn = var.intVal;}var = pStationRecordset->GetCollect(_T("entryshift"));//tinyintif((var.vt == VT_I2) || var.vt == VT_I4){nSn1 = var.intVal;}var = pStationRecordset->GetCollect(_T("recordno"));//intif((var.vt == VT_I2) || var.vt == VT_I4){nSn2 = var.intVal;} var = pStationRecordset->GetCollect(_T("MVlicense"));//Varcharif(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);  }  




0 0