ADO查询站SQLServer,字段类型

13 篇文章 0 订阅
5 篇文章 0 订阅

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);  
	}  




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值