当我将SQL从VB6代码复制到Foxpro中时,我正在将SQL insert语句写到Foxpro中,没有问题。当我使用相同的SQL并将其复制到测试程序时,它没有插入任何问题。当我在原始程序中执行SQL时,我得到“命令包含无法识别的短语/关键字”。
cnSO就是我在测试程序中使用的connection对象,与我在实时程序中使用的连接字符串相同。
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","","")发布于 2017-06-23 01:46:23
在VFP语言中,用来填充表中给定字段的replace函数。我想你应该用'代替",如果是这样的话,你应该使用STRTRAN(string to transform, string to seek, string to replace)
insertSQL = "insert into soordeht (" & insertFields & ") values (" & STRTRAN(insertData, '"', "'") & ")"请注意,第二个参数是包含在' '中的",第三个参数是包含在" "中的',这是因为您需要以不同的方式包含' enclosure‘,或者像您第一次那样调用CHR(34)函数。
https://stackoverflow.com/questions/42002801
复制相似问题