ADO学习

使用了OLE ADO动态链接库。必须在stadafx.h中加入
   #import "C:/program files/common files/system/ado/msado15.dll"/
   no_namespace rename("EOF","adoEOF")
加入了动态库msado15.dll动态库后需要在初始化函数中初始化OLE/COM环境库。
InitInstance()中加入:
     if (!AfxOleInit())
{
   AfxMessageBox("初始化OLE DLL 失败:(");
   return FALSE;
}
OLE DB提供者实现对SQL Sever的标准安全连接串:
CString strConnect;
   strConnect=_T("Provider=sqloledb;Data Source=file;"
   "Initial Catalog=file;"
   "User ID=MyUserName;Password=Mypassword;");
打开记录集:
BOOL CInternetBarApp::OpenRecordSet(_RecordsetPtr &recPtr,CString &strSQL)
{
     CInternetBarApp* pApp=(CInternetBarApp*)AfxGetApp();
     m_pRecordset.CreateInstance(_uuidof(Recordset));
try
     {
   recPtr->Open(strSQL.AllocSysString(),m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
}
catch(_com_error e)
{
   CString strError;
   strError.Format("警告:打开数据库表时发生异常。错误信息:%s",e.ErrorMessage());
   AfxMessageBox(strError);
   return FALSE;
}
return TRUE;
}
vc获得系统当前时间:
CTime   time=CTime::GetCurrentTime();  
   CString   str;  
   str.Format("Years:   %d   Months:   %d   Days:   %d,   Hours:%d   Minutes:%d,   Seconds:%d",   time.GetYear(),   time.GetMonth(),   time.GetDay(),   time.GetHour(),   time.GetMinute(),  
time.GetSecond());  
vc中获得系统时间转换成sql   server表中datetime类型
   (1)COleDateTime   oletimeVar;  
   _variant_t   var;  
   给oletimeVar赋值;  
   var.vt=VT_DATE;  
   var.date=DATE(oletimeVar);  
   然后将var作为参数传入到你要添加的语句中
   (2)COleDateTime ole_time=COleDateTime::GetCurrentTime();  
   CString szTime;  
   szTime=ole_time.Format(VAR_DATEVALUEONLY);  
   rs_write.m_rs->PutCollect("SellDate",_variant_t(szTime));  
   rs_write.m_rs->Update();
将一个_variant_t类型的值转化为一个CString
   COleVariant var=_variant_t  
   CString str=var.bstrVal  
   OR  
   (LPCTSTR)(_bstr_t)vType  

PS:没经验写点东西就是慢,还要花掉大量时间DEBUG。积累经验很重要。 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值