zoukankan      html  css  js  c++  java
  • ADO读写DateTime方式

    // 读取日期
    var = m_pResultSet->GetCollect(_variant_t("Birth_Time"));
         
    DATE            dt      = var.date;
    COleDateTime    da      = COleDateTime(dt);
    CString         strData = da.Format(_T("%Y-%m-%d"));
    m_GridList.SetItemText(m_nRow, m_nColumn, strData);
     
     
    // 写入日期
    COleDateTime    oleDate = COleDateTime::GetCurrentTime();
    CString         strDate = oleDate.Format(_T("%Y-%m-%d %H:%M:%S"));
     
    m_pBorrowRS->Fields->GetItem(_variant_t("Borrow_Date"))->PutValue(_variant_t(strDate));    
    m_GridList.SetItemText(m_nRow, m_nColumn, strDate);
     
    或:
    COleDateTime    oleDate = COleDateTime::GetCurrentTime();
     
    _variant_t  vtDate;
    vtDate.vt   = VT_DATE;
    vtDate      = oleDate.Format(_T("%Y-%m-%d %H:%M:%S"));
     
    m_pBorrowRS->Fields->GetItem(_variant_t("Borrow_Date"))->PutValue(vtDate);
    m_GridList.SetItemText(m_nRow, 3, (LPCTSTR)_bstr_t(vtDate));
     COleDateTime::GetCurrentTime()        var.date                
    
                                                             /                 
    
                                                           /                  
    
                                                         /                   
    
                                    COleDateTime  oleDate;                                            
    
                                            /                                
    
                                          /                                  
    
                                        /                         
    
                  var = oleDate.Format(...)     strDate = oleDate.Format(...)

    也可以是用sql语句直接插入的方式:

    strSql.Format(_T("update SESSIONS set BLOGGEDON = 0 ,DATE_LOGOFF = to_date('%s', 'YYYY/MM/DD HH24:MI:SS')  where ID = '%s'"),

    这就是直接插入时间了 

    ps:

    检查字符串是否为空

    FieldPtr filedptrTmp = m_pRecordset->Fields->GetItem((_bstr_t)(LPCTSTR)m_strDatabaseTheoryWeight);
       if ((filedptrTmp->Value.vt != VT_NULL) && (filedptrTmp->Value.vt != VT_EMPTY))
        FieldPtr filedptrTmp = 。。。。
  • 相关阅读:
    Linux之Shell基本命令
    Linux之find命令
    C++11 auto类型说明符
    C++之类型转换
    C++中指针和引用的区别
    C++之引用
    [BUUCTF]PWN——[ZJCTF 2019]EasyHeap
    [BUUCTF]REVERSE——[WUSTCTF2020]level3
    [BUUCTF]REVERSE——[MRCTF2020]hello_world_go
    [BUUCTF]REVERSE——[GKCTF2020]BabyDriver
  • 原文地址:https://www.cnblogs.com/liaocheng/p/4778677.html
Copyright © 2011-2022 走看看