cstring format 里面哪里有错误? (急)

starsky_1 2008-12-12 09:38:22
sql.Format ("SET NOCOUNT ON declare @num int set @num=0 select 线路号, 站点名, 路线=cast('('+线路号+':'+站点名 as varchar(4000)), 序号=序号, tt=@num into # from 线路站点 where 站点名='%s'; while @@rowcount>0 and not exists (select * from # where 站点名='%s') begin set @num=@num+1 insert into #(路线,线路号,站点名,序号,tt) select 路线=a.路线+case when a.线路号=b.线路号 then '->'+b.站点名 else ')转('+b.线路号+':'+b.站点名 end, b.线路号,b.站点名,b.序号,@num from # a, 线路站点 b where a.tt=@num-1 and(a.站点名=b.站点名 and a.线路号 <>b.线路号 or a.线路号=b.线路号 and (a.序号=b.序号+1 or a.序号=b.序号-1)) and len(a.路线) <4000 and patindex('%[ >]'+b.站点名+'[-)]%',a.路线)=0 end select '路线'=路线+')' from # where tt=@num and 站点名='%s' if @@rowcount =0 select * from # ;drop table #;",station_start,station_end,station_end);

比较长了点 但不是错误吧?
那到底哪里出错了?
...全文
106 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
CodeProject-Jerry 2008-12-13
  • 打赏
  • 举报
回复
你不知道分行写啊 你这种写法怎么看得懂啊???



CString strA;
strA.Format( _T("SET NOCOUNT ON ")
_T("declare @num int ")
_T("set @num=0 ")
_T("select 线路号, 站点名, 路线=cast('('+线路号+':'+站点名 as varchar(4000)), 序号=序号, tt=@num into # from 线路站点 where 站点名='%s'; ")
// ....
, 参数1
, 参数2
, // ...
);


你的代码之所以会报错 肯定是因为中间某一个或者多个格式化参数的类型写错了, 比如是格式化int形,你写成了 %s

你最好全部删掉,一段一段地加上去,定位到出错的位置
lhsxsh 2008-12-13
  • 打赏
  • 举报
回复
应该是串并不有问题,好好查下,
建议把分成几小段出来再看看。
菜牛 2008-12-12
  • 打赏
  • 举报
回复
我看还是转义符问题,格式化字符串中%要用%%表示。
luowin 2008-12-12
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 sys0006 的回复:]
内存泄漏跟Format没关系的。
[/Quote]
打断点在format,应该不是format的原因,是不是你丢SQL发生的内泻呢?
sys0006 2008-12-12
  • 打赏
  • 举报
回复
内存泄漏跟Format没关系的。
starsky_1 2008-12-12
  • 打赏
  • 举报
回复
我都转义了 还是不行
好像提示那个英文说 内存泄漏 之类的
怎么办?
哪出的问题?
sys0006 2008-12-12
  • 打赏
  • 举报
回复
Format里的'要转义,写成\'
例如:
test.Format(_T("name = \'%s\'"), _T("test"));
shailen126 2008-12-12
  • 打赏
  • 举报
回复
VC中有关数据库操作的程序有时会发生很离谱的问题的,所以我觉得不一定是Format的问题,有可能是数据库操作产生的问题
给你提一个小方案来测一下:你可以再建一个工程简单测一下这个Format语句,看看有没有错,这样你就可以定位问题是不是出在这条语句上了。。。
scutLiu 2008-12-12
  • 打赏
  • 举报
回复
个人感觉是里面的中文的问题
呵呵……
TearyWang 2008-12-12
  • 打赏
  • 举报
回复
双引号中的单引号不需要使用转意符号。
问题出在这里:
sql.Format ("SET NOCOUNT ON declare @num int set @num=0 select 线路号, 站点名, 路线=cast('('+线路号+':'+站点名 as varchar(4000)), 序号=序号, tt=@num into # from 线路站点 where 站点名='%s'; while @@rowcount>0 and not exists (select * from # where 站点名='%s') begin set @num=@num+1 insert into #(路线,线路号,站点名,序号,tt) select 路线=a.路线+case when a.线路号=b.线路号 then '->'+b.站点名 else ')转('+b.线路号+':'+b.站点名 end, b.线路号,b.站点名,b.序号,@num from # a, 线路站点 b where a.tt=@num-1 and(a.站点名=b.站点名 and a.线路号 <>b.线路号 or a.线路号=b.线路号 and (a.序号=b.序号+1 or a.序号=b.序号-1)) and len(a.路线) <4000 and patindex('%[ >]'+b.站点名+'[-)]%',a.路线)=0 end select '路线'=路线+')' from # where tt=@num and 站点名='%s' if @@rowcount =0 select * from # ;drop table #;",station_start,station_end,station_end);

%符号需要用%%来代替

16,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

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