往一个表中插入数据为什么只插一个字段就可以,而插两个字段就怎么也插不进去呢?
代码如下:
////////////////////////可以插进去的代码//////////////////////////
CString insertSql;
insertSql.Format("INSERT INTO users(NAME) VALUES ('%s')",m_userName);
_bstr_t insertSQL = insertSql;
try
{
m_pRecordset.CreateInstance("ADODB.Recordset");
m_pRecordset->Open(insertSQL,_variant_t((IDispatch*)    m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
MessageBox("注册成功!","注册用户");
}//////////////////////插不进去的代码/////////////////////////////
CString insertSql;
insertSql.Format("INSERT INTO users(NAME PASSWORD) VALUES ('%s','%s')",m_userName,m_password);
_bstr_t insertSQL = insertSql;
try
{
m_pRecordset.CreateInstance("ADODB.Recordset");
m_pRecordset->Open(insertSQL,_variant_t((IDispatch*)    m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
MessageBox("注册成功!","注册用户");
}表里就两个字段 NAME PASSWORD太郁闷了!!!!!!!!!!!!!!!!!!!!!!!
}

解决方案 »

  1.   

    如果执行一个sql语句 用不着recordset对象 直接用conn的Execute()就可以
      

  2.   

    NAME PASSWORD 之间是否应该有个 , 号
      

  3.   

    INSERT INTO users(NAME, PASSWORD) VALUES ('%s','%s')
      

  4.   

    _bstr_t insertSQL = insertSql;
    改成
    _bstr_t insertSQL = insertSql.AllocSysString();
      

  5.   

    坚决同意 ruihuahan(飞不起来的笨鸟)!
      

  6.   

    Allocates a new OLE Automation–compatible string of the type BSTR and copies the contents of the CString object into it, including the terminating null character. A CMemoryException is thrown if insufficient memory exists. This function is normally used to return strings for OLE Automation.Use ::SysFreeString in the rare case that you need to deallocate the returned string.Note   You must link with MFCO42D.DLL to obtain this function if you are using MFC in a shared library and building in debug mode. You can cause the linker to get MFCO42D.DLL automatically by including <afxdisp.h> in your STDAFX.H file.
      

  7.   

    ruihuahan(飞不起来的笨鸟):
    还是不行,相似的代码对其他表的操作就没问题
    到底出什么鬼了?郁闷中!!!!
      

  8.   

    看看表字段的类型,难道PASSWORD是关键字?http://expert.csdn.net/Expert/topic/2062/2062586.xml?temp=.861294
    麻烦大家看一下
      

  9.   

    手工用SQL语句插入试一下,确定表可以插入,和语句是否正确,在从程序里找错误!
      

  10.   

    把表删除掉,重建一下,试试看例外,考虑一下把字段名该成 Name1 Pass1试试