C++操作SQL2005更新数据库时出错!高手们请进!

l546461042 2011-03-22 02:21:05
提示错误:IDispatch error:#3092
网上搜了 说的是字段类型不匹配,我看我字段类型也没哪不匹配 给解决下!谢谢!
代码如下:
#include <string>
using namespace std;
#include <tchar.h>
#import "c:\Program Files\Common Files\System\ADO\msado15.dll" \
no_namespace rename("EOF", "EndOfFile")
void main()
{
string codenum="00001";
::CoInitialize(NULL);
_bstr_t strCnn("Provider=SQLOLEDB.1;Data Source=(local);Initial Catalog=userInfo;User Id=sa;Password=123;");
_ConnectionPtr pConnection = NULL;
try
{
pConnection.CreateInstance(__uuidof(Connection));
pConnection->Open (strCnn, "", "", adConnectUnspecified);
string str="UPDATE bookStore SET 证书路劲='ct_cer"+codenum+"' WHERE 用户编号='"+codenum+"'";
_bstr_t strUpdate=_T(str.c_str());
pConnection->Execute(strUpdate,NULL,adCmdText);
}
catch(_com_error e)
{
printf(_T("Warning: Execute方法发生异常. 错误信息: %s; 文件: %s; 行: %d\n"), e.ErrorMessage(), __FILE__, __LINE__);
}
}
...全文
120 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
l546461042 2011-03-22
  • 打赏
  • 举报
回复
问题已解决:
#include <iostream>
#include <string>
using namespace std;
#include <tchar.h>
#import "c:\Program Files\Common Files\System\ADO\msado15.dll" \
no_namespace rename("EOF", "EndOfFile")
void main()
{
string codenum="00001";
::CoInitialize(NULL);
_bstr_t strCnn("Provider=SQLOLEDB.1;Data Source=(local);Initial Catalog=userInfo;User Id=sa;Password=123;");
//_bstr_t bstrSQL(_T("select 用户编号,国家,省份,城市,姓名,证书路径 from bookStore"));
_ConnectionPtr pConnection = NULL;
_RecordsetPtr pRstTitles = NULL;
try
{
pConnection.CreateInstance(__uuidof(Connection));
pConnection->Open (strCnn, "", "", adConnectUnspecified);
string str="UPDATE bookStore SET 证书路径='ct_cer"+codenum+"' WHERE 用户编号='"+codenum+"'";
_bstr_t strUpdate=_T(str.c_str());
pConnection->Execute(strUpdate,NULL,adCmdText);
pConnection->Close();
}
catch(_com_error e)
{
//printf(_T("Warning: Execute方法发生异常. 错误信息: %s; 文件: %s; 行: %d\n"), e.ErrorMessage(), __FILE__, __LINE__);
cout<<(string)(e.Description())<<endl;
}
}
不会的也参考哈!呵呵
wonderhui 2011-03-22
  • 打赏
  • 举报
回复
不是吧,我记得我查过#3092是指目标表已存在啊。。。。
sg_knight 2011-03-22
  • 打赏
  • 举报
回复
怎么使用中文字段,改用英文好了。
zxhx 2011-03-22
  • 打赏
  • 举报
回复
有中文出现的地方最好都转化一下:

string str=_T("UPDATE bookStore SET 证书路劲='ct_cer")+codenum+_T("' WHERE 用户编号='")+codenum+"'";
zyq5945 2011-03-22
  • 打赏
  • 举报
回复
感觉应该是SQL语句可能有问题,看错误这样改下就好了。
e.ErrorMessage()
//--?
e.Description()

cpp2017 2011-03-22
  • 打赏
  • 举报
回复
跟踪一下sql的值,执行一下看看有没有问题,另你使用的中文字段?而且路径写成了
“路劲”?

4,011

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 数据库
社区管理员
  • 数据库
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧