要用一个CSTRING的类型的数据进行格式化,然后再执行SQL语句。

解决方案 »

  1.   

    我那个sSql变量不就CString类型的么?
      

  2.   

    head.MailAddress,head.MailID,head.From,head.Subject,head.Date
    的类型都是字符串型('%s')吗?
      

  3.   

    看看他的说明吧:
    CDatabase::ExecuteSQL
    void ExecuteSQL( LPCSTR lpszSQL );
    throw( CDBException );ParameterslpszSQLPointer to a null-terminated string containing a valid SQL command to execute. You can pass a CString.ResCall this member function when you need to execute an SQL command directly. Create the command as a null-terminated string. ExecuteSQL does not return data records. If you want to operate on records, use a recordset object instead.Most of your commands for a data source are issued through recordset objects, which support commands for selecting data, inserting new records, deleting records, and editing records. However, not all ODBC functionality is directly supported by the database classes, so you may at times need to make a direct SQL call with ExecuteSQL.ExampleCString strCmd = "UPDATE Taxes SET Federal = 36%";TRY
    {
       m_dbCust.ExecuteSQL( strCmd );
    }CATCH(CDBException, e)
    {
       // The error code is in e->m_nRetCode
    }END_CATCH
      

  4.   

    日期类型格式化错了,如果是ACCESS数据库,应该是
    sSql.Format("insert into mail (MailAddress,MailID,Check,From,Subject,Date,Size) values ('%s','%s',0,'%s','%s',CDate('%s'),%d)",
    head.MailAddress,head.MailID,head.From,head.Subject,head.Date,head.Size);
    注意,应该是CDate('%s')而不是'%s'
      

  5.   

    我在ACCESS库里的日期是作为字符串来保存的
    head.MailAddress,head.MailID,head.From,head.Subject,head.Date都是字符串类型
      

  6.   

    为什么日期要用字符串来保存??建议你逐个字段insert调试一下,看是在哪个字段insert的时候出错
      

  7.   

    values ... ,#2000-1-12 18:00:00# ,.....
      

  8.   

    老兄你用的是什么数据库?SQL Server 用‘’而Access应该用#号。