我在Foxpro中编写一个SQL插入语句,当我将插入的VB6代码中的SQL复制到Foxpro时没问题。当我使用相同的SQL并将其复制到测试程序时,它不会插入任何问题。当我在原始程序中执行SQL时,我得到"命令包含无法识别的短语/关键字"。
cnSO就是连接对象,我在测试程序中使用了与实时程序中相同的连接字符串。
insertSQL = "insert into soordeht (" & insertFields & ") values (" & Replace(insertData, Chr(34), "'") & ")"
Debug.Print insertSQL
'Debug.Print (insertFields)
'Debug.Print (insertData)
cnSO.Execute ("set null off")
cnSO.Execute (insertSQL)
这是输出的SQL
insert into soordeht (ordnum,number,orddate,time,ordtype,origin,name,address1,credline1,address2,city,state,zip,country,contact,tcode_1,tcode_2,tcode_3,agginvoice,division,discperc,taxzone,shipcode,shipname,shipadd1,shipadd2,shipcity,shipst,shipzip,shipctry,shipphone,shiparea,dist_ctr,store_no,dept_num,consacct,shipaymeth,billname,billadd1,billadd2,billcity,billst,billzip,billphone,custponum,cred1or2,shipvia,termcode,whnum,prtstatus,invoiceprt,orderprt,packprt,userid,slpcode,slpcomm,slpperc,comtype,compaid,comchgpcnt,comchgdays,comchgwarn,deldate,fax,areafax,source,trans_num,cross_dock,shipref,numlabels,paytype,shipstatus,status,fre_tax,trackingno,comment) values ("20026513","02658",{^2017-01-20},"11:37PM","S","L","KIDS ROOM, INC","GARY AND ED GOTLIEB","GARY AND ED GOTLIEB","5801 WESTHEIMER","HOUSTON","TX","77005","","GARY AND ED","00","00","00",.F.,"00",0,"","70290","C&S WHOLESALE GROCERS","OLD FERRY ROAD","","BRATTLEBORO","VT","05301","","","","","","","","","","","","","","","","722480","N ","","CC","DEF","Y",.T.,.T.,.T.,"SUP","HOU",5,100,"",0,0,0,0,{^2017-02-21},"","","ED^","35417","","",0,0,"Y","S","N","","")
答案 0 :(得分:0)
在VFP中,replace
函数用于填充表格的给定字段,恕我直言,我认为您要将"
替换为'
,如果是,你应该使用STRTRAN(string to transform, string to seek, string to replace)
:
insertSQL = "insert into soordeht (" & insertFields & ") values (" & STRTRAN(insertData, '"', "'") & ")"
请注意,第二个参数"
包含在' '
中,第三个参数'
包含在" "
中,因为您需要封装'围栏'以不同的方式,或者像你先做的那样,调用CHR(34)
函数。