2 changemememe ChangeMememe 于 2014.12.19 22:59 提问

怎么把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();
}

3个回答

fanhongjun2004
fanhongjun2004   2014.12.22 16:49

CTime先转换为CString ,再转换为variant

caozhy
caozhy   Ds   Rxr 2015.01.03 07:09

也可以用CTime先format再构造sql插入

caozhy
caozhy   Ds   Rxr 2015.01.03 07:10
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!