问题描述
- 怎么把MFC CTime类型变量插入数据库的datetime中?
-
UpdateData(true);
ADOConn m_adoConn;
m_AdoConn.OnInitADOConn();
_bstr_t sql;
sql="select * from Records";
m_pRecordset=m_AdoConn.GetRecordSet(sql);
int pos=m_ctrList.GetSelectionMark();
try
{m_pRecordset->Move((long)pos,vtMissing);//移动记录集指针位置 //设置记录集 m_pRecordset->PutCollect("CustomerID",(_bstr_t)dlg.m_CustomerID); m_pRecordset->PutCollect("CustomerName",(_bstr_t)dlg.m_CustomerName); m_pRecordset->PutCollect("RoonNo",(_bstr_t)dlg.m_RoonNo); m_pRecordset->PutCollect("RoomTypeName",(_bstr_t)dlg.m_RoomType); m_pRecordset->PutCollect("Price",(_bstr_t)dlg.m_Price); m_pRecordset->PutCollect("RuzhuDate",(_bstr_t)dlg.m_RuzhuDate);//这句报错error C2440: 'type cast' : cannot convert from 'class CTime' to 'class _bstr_t' m_pRecordset->PutCollect("Jiesuandate",(_bstr_t)dlg.m_JiesuanDate);//这句报错error C2440: 'type cast' : cannot convert from 'class CTime' to 'class _bstr_t' m_pRecordset->PutCollect("TotalPrice",(_bstr_t)dlg.m_Money2); m_pRecordset->Update(); //更新记录集 m_AdoConn.ExitConnect(); //断开数据库连接 } catch(...) { MessageBox("操作失败"); return; } MessageBox("保存成功。"); m_ctrList.DeleteAllItems(); AddToList(); }
解决方案
CTime先转换为CString ,再转换为variant
解决方案二:
也可以用CTime先format再构造sql插入
解决方案三:
http://www.cnblogs.com/joeblackzqq/archive/2010/11/08/1872209.html
时间: 2024-10-30 01:48:34