您的位置:程序门 -> vb -> vba



特殊符号该如何处理


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


特殊符号该如何处理[已结贴,结贴人:vivific2003]
发表于:2007-07-17 20:45:42 楼主
当数据里含有单引号 '这样的特殊符号时,执行代码时就会提示错误,该如何处理这种特殊符号的问题呢?
以上谢谢!
发表于:2007-07-17 21:12:451楼 得分:10
你是不是说的sql查询阿
replace(str, " ' ", " ' ' ")
这样就好了
发表于:2007-07-17 23:20:082楼 得分:10
当您想要新增一笔资料到   access   或   oracle   时,若文字栏位中含有单引号,便会产生错误!

在以下的例子中,我们告诉您如何使用   chr$(34)   将含有单引号之字串存入   jet   database   engine   中!

private   sub   cmdaddnew_click()
dim   dbcustomer   as   database   '   声明资料库
dim   strsql   as   string   '   sql   字串
dim   strodbc   as   string   '   odbc   字串

'   以下为资料库中客户档之三个栏位变量声明
dim   strcustid   as   string   '   客户代码
dim   strfirstname   as   string   '   客户名称
dim   straddress   as   string   '   客户地址

strodbc   =   "odbc;uid=scott;pwd=tiger;dsn=myconnect "
set   dbcustomer   =   opendatabase( "myconnect ",   dbdrivernoprompt,   false,   strodbc)

strcustid   =   "a003 "
strfirstname   =   "annie "
straddress   =   "reflection 's "

strsql   =   "insert   into   customer   values( ' "   &   strcustid   &   " ' "
strsql   =   strsql   &   ", ' "   &   strfirstname   &   " ', "
strsql   =   strsql   &   chr(34)   &   straddress   &   chr(34)   &   ") "

dbcustomer.EXECute   (strsql)
dbcustomer.close
end   sub

'如果您还想要更详细的资料,您可以参考   microsoft   knowledge   base   中的   q147687。
发表于:2007-07-18 07:35:463楼 得分:0
两位谢谢了!


快速检索

最新资讯
热门点击