求助:Execute失败!错误信息:IDispatch error #3119
用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个表操作不能这么做?
------解决方案--------------------如果字段没写错的话,看看是不是数据类型不匹配
------解决方案--------------------如果longitude1,latitude1是字符或日期型,后面的值两侧需要加单引号,如:
str2= " VALUES ( ' "+str_longi1+ " ', ' "+str_latit1+ " ') "; --你的第一个括号应该是英文的才对