我用ole db客户端连接sql server2000 其中有两个表:
其表一是向表中插入一条记录时关键字ID号自动按顺序生成 有三个字段:keyid,username,password
其表二是向表中插入一条记录时关键字ID号自己添加 有三个字段 username ,password,date(关键字)
当进行插入操作时发现:
表一操作不成功,而表二成功! 请指点迷津!
代码如下:
其中 cmdTable1,cmdTable2都是command
 CString strSql;
HRESULT hr;
strSql.Format("select * from table1 where username= '%s' and password = '%s'",m_user,m_pass);
hr=m_cmdTable1.Open(m_sessionSqlserver,strSql,&m_propset);
if(hr!=S_OK)
  return false;
m_cmdTable1.Movelast();
strcpy(m_cmdTable1.m_username,"10001");
strcpy(m_cmdTable1.m_username,"000000");
hr= m_cmdTable1.Insert();
if(hr!=S_OK)
{
m_cmdTable1.Close();
return FALSE;
}
结果是 hr = -2346877 记录插入失败]而表二
 CString strSql;
HRESULT hr;
CTime time = CTime::GetCurrentTime();
CString strdate = time.Format("20%y%m%d%H%M");
strSql.Format("select * from table1 where date= '%s' and username= '%s' and password = '%s'",strdate,m_user,m_pass);
hr=m_cmdTable2.Open(m_sessionSqlserver,strSql,&m_propset);
if(hr!=S_OK)
  return false;
m_cmdTable2.Movelast();
strcpy(m_cmdTable2.m_date,strdate);
strcpy(m_cmdTable2.m_username,"10001");
strcpy(m_cmdTable2.m_username,"000000");
hr= m_cmdTable2.Insert();
if(hr!=S_OK)
{
m_cmdTable2.Close();
return FALSE;
}结果是 hr=0 记录插入成功.