VC中ADO可执行的SQL的长度有限制么?

powerking2 2007-11-07 01:24:22
1、现在需要给数据库中插入记录,由于每一条记录的字段比较多,并且有几个字段的值(字符串)也比较长,大概一条记录最后生成的SQL串有2000多个字符,每次执行插入都回报错,可是我把抱错的SQL语句写进文件中,在查询分析器中执行是正确的。这说明SQL语句是没有问题的,但是如果SQL串短点九不会抱错,怀疑是不是ADO对可执行的SQL串的长度有限制?
2、我是用ADODB::Connection15ptr 这个智能指针的Execute方法直接插入的!
...全文
233 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
liee96 2007-11-07
  • 打赏
  • 举报
回复
语法好象没有什么问题,你用这个SQL试试再说

insert into temsubject (title,author,authoraffiliation,source,publicationyear,publisher,issn,languages,DocumentType,pages,country,abstract,topic,accessionnumber,databasename ) values ( 'Internet function and Internet addictive behavior ', 'Li, Shih-Ming; Chung, Teng-Ming ', 'Department of Psychology, National Chung-Cheng University, Chia-Yi, Taiwan ', 'Computers in Human Behavior,v 22,16,p 1067-1071,November 2006. ', '2006 ', 'Elsevier Ltd, Oxford, OX5 1GB, United Kingdom ', '0747-5632 ', 'English ', 'Journal article (JA) ', 'p 1067-1071 ', ' ', '(long sentence)', 'Human computer interaction,Internet - Students - Social aspects - Problem solving - Health,Addiction - Interpersonal - Virtual emotional function. ', '06189859669 ', 'EI ')
shakaqrj 2007-11-07
  • 打赏
  • 举报
回复
看的头晕

你把values后面的东西,一点一点地代换
一开始全部换成'1',看看出不出错
然后慢慢来
我只想到这么办了。。。
powerking2 2007-11-07
  • 打赏
  • 举报
回复
走过路过的大侠,都帮忙顶下阿,不胜感激中。。。。。。
powerking2 2007-11-07
  • 打赏
  • 举报
回复
还需要看源码?

那我就贴上来了?

下面是我要执行的SQL语句(有点长阿)
insert into temsubject (title,author,authoraffiliation,source,publicationyear,publisher,issn,languages,DocumentType,pages,country,abstract,topic,accessionnumber,databasename ) values ( 'Internet function and Internet addictive behavior','Li, Shih-Ming; Chung, Teng-Ming ','Department of Psychology, National Chung-Cheng University, Chia-Yi, Taiwan ','Computers in Human Behavior,v 22,16,p 1067-1071,November 2006.','2006','Elsevier Ltd, Oxford, OX5 1GB, United Kingdom','0747-5632','English','Journal article (JA)','p 1067-1071','','Ju [Research on personal characteristics, the behavior of using Internet and Internet addiction for Taiwanese college study. Master thesis. Taiwan, 2000] found the Internet function was related to the severity of Internet addiction, and this study explored the relationship between the Internet function and the Internet addictive behavior. Seventy-six college students were included in this study and had completed the Internet use function questionnaire (social function, informational function, leisure function and the virtual emotional function) and the Chinese Internet Addiction Scale (compulsive use, withdrawal, tolerance, time management problem and interpersonal and health problems). The study revealed not only the relationship between the social function and the index of the Internet dependence (compulsive use, withdrawal, tolerance and the problems in the interpersonal relationship and health), but also the correlation between the information function and the index of the Internet abuse (the problems in the interpersonal relationship and health). We found the social function played the core role in the Internet addictive behavior and the mechanism needs further discussion. © 2004 Elsevier Ltd. All rights reserved.','Human computer interaction,Internet  -  Students  -  Social aspects  -  Problem solving  -  Health,Addiction  -  Interpersonal  -  Virtual emotional function.','06189859669','EI')

----------------------------------------------------------------------------------------------
代码:
::ADODB::Connection15Ptr pConn;
HRESULT hr= pConn.CreateInstance(__uuidof(ADODB::Connection));
if( FAILED(hr))
{
return FALSE;
}

CString ConnStr = GetConnectionString();

hr = pConn->Open((_bstr_t)ConnStr,_bstr_t(L""),_bstr_t(L""),ADODB::adModeUnknown);

VARIANT *vt1 = NULL;
_bstr_t bstr(上面的那个SQL语句);
pConn->Execute(bstr,vt1,ADODB::adCmdText);
zaodt 2007-11-07
  • 打赏
  • 举报
回复
用存储过程
coffeaddice 2007-11-07
  • 打赏
  • 举报
回复
SQL语句 在查询分析器可以执行

但是在vc 操作数据库时 并不一定所有的都可以执行

我上次用ado操作数据库,在查询分析器里可以执行

但是拷贝到vc中 用CString strSQL.format()

格式化执行此语句 错误 因为里面 distinct 不支持

后来自己用vc代码写的了个算法

access和sql在vc中的时间比较条件格式也不一样

建议你就先把insert 拆成短句 然后加条件啊
shakaqrj 2007-11-07
  • 打赏
  • 举报
回复
另外需要看你的比较完整的代码

shakaqrj 2007-11-07
  • 打赏
  • 举报
回复
我以前遇到过更奇怪的现象
insert的字符串莫名其妙的消失一段,如果调换顺序,那就没有错

2000多个字符...汗
本来还想看看你的sql,现在....
算了,还是把你的sql贴出来吧
powerking2 2007-11-07
  • 打赏
  • 举报
回复
各位大侠,看见的都帮忙顶下阿
powerking2 2007-11-07
  • 打赏
  • 举报
回复
我现在是用insert插入数据,我把出错的语句写到 文件中,然后在Sql server的查询分析器中执行都可以阿;我想在查询分析器里可以执行,应该没有语法错误吧
LanglyTiger 2007-11-07
  • 打赏
  • 举报
回复
可能有些语法不支持,楼上的方法不错
coffeaddice 2007-11-07
  • 打赏
  • 举报
回复
有些东西可能不支持

象 distinct 就不可以直接用
而且 有些字符 /\ 之类的不识别
我以前用ado的时候 表名:05/06需求库 查询时就有错误 就是那个/需要处理


这些小问题 你看看 有没有 长度我没有用过那么长的 不知道

或者 你把长句缩短

从最短的开始写
例如: 先写 select * from tab
然后 一点点加条件
看加到哪里的时候出错 再对应找错误
powerking2 2007-11-07
  • 打赏
  • 举报
回复
自己帮自己先顶下

4,017

社区成员

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

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