用MFC编制的程序通过ADO调用SQL Server。我在一个按钮的相应函数里先后对同一个数据库的两个表做INSERT操作,但对第二个表做INSERT时在代码(*)行出现题目的错误提示,代码简要:
_ConnectionPtr m_pConnection;
::CoInitialize(NULL);
try
{
    m_pConnection.CreateInstance("ADODB.Connection");
    if (m_pConnection == NULL)
    { 
      AfxMessageBox("失败! \r\n");
      return;
    }
    ASSERT(m_pConnection != NULL);
    _bstr_t strConnect="Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=Car";
    m_pConnection->Open(strConnect,"","",adModeUnknown);//adModeUnknown
}
catch(_com_error e1)
{
    CString errormessage;
    errormessage.Format("错误信息:%s",e1.ErrorMessage());
    AfxMessageBox(errormessage);
    return;
}
//==========================================
//     向表Move写入数据
//==========================================
_bstr_t vSQL;
CString str1,str2;
str1="INSERT INTO Move(\
longitude,latitude)";
str2=" VALUES ("+str_longi0+","+str_latit0+") ";
vSQL=str1+str2;
//执行INSERT语句
try
{
    m_pConnection->Execute(vSQL,NULL,adCmdText);
}
catch(_com_error e2)
{
    CString errormessage;
    errormessage.Format("错误信息:%s",e2.ErrorMessage());
    AfxMessageBox(errormessage);
    return;
}
//==========================================
//     向表Navi写入数据
//==========================================
str1="INSERT INTO Navi(\
longitude1,latitude1)";
str2=" VALUES ("+str_longi1+","+str_latit1+") ";
vSQL=str1+str2;
try
{
    m_pConnection->Execute(vSQL,NULL,adCmdText);  
                              /////////////////////////////////(*)
}
catch(_com_error e2)
{
    CString errormessage;
    errormessage.Format("错误信息:%s",e2.ErrorMessage());
    AfxMessageBox(errormessage);
    return;
}
m_pConnection->Close();
::CoUninitialize();请教这个错误是为什么呢?是不是先后对同1个数据库的2个表操作不能这么做?

解决方案 »

  1.   

    现在查询分析器中执行SQL语句看看,是否能够成功。
      

  2.   

    是这样的:
    表Move除了有2个列段:
    longitude,latitude外还有个主键move_id,
    而表Navi同样除了2个列段:
    longitude1,latitude1还设了个主键navi_id,
    我把navi_id这个主键删掉程序就可以正常运行了,可我的目的就是通过move_id和navi_id这两个主键将两个表联合起来,这样删去navi_id的话,该怎么联合呢?