| 发表于: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。 | | |
|