单引号,咋就无法执行了?数据中包含单引号?如果不是数据包含,使用:sql="select * from table1 where username='" & text1.text & "'"
这样: '避免出现用户名中有"'"干扰sql查询语句出错 dim strA() as string strA = Split(txtUsername.Text, "'") '如果含有"'"就会把字符串截开,赋值到数组 If UBound(strA) <> 0 Then MsgBox "用户名中有非法字符,请重新输入!", vbOKOnly + vbExclamation, "警告" Exit Sub End If
或者:Private Sub txtUserID_Change() '限制输入非法字符 dim bJudge as boolean bJudge = txtUserID Like "*'*" If bJudge Then MsgBox "请不要输入非法字符!", vbOKOnly + vbExclamation, "警告" End If End Sub
如果你的text1中包含单引号的话,具体哪个是字段内容就表示不明,易报错
如果是为了防止Text1中包含',可以使用以下语法,将'过滤掉 sql="select * from table1 where username='" &amp; Replace(text1.text,"'","")……
sql="select * from table1 where username=" & chr(39) & text1.text & chr(39)
strSQL = "Update t_DeliverNote_temp Set RealAmount=? "
strSQL = strSQL + ",UnitCN=?,UnitEN=?,Amount=? "
strSQL = strSQL + " Where DNNumber=? And JDE_Code=?"
strSQL = strSQL + " And Sequency=?"
Dim adocmd As New ADODB.Command
adocmd.ActiveConnection = objADOConn
adocmd.CommandText = strSQL
adocmd.Parameters.Item(0).Value = CSng(Val(.TextMatrix(intRow, DNModify.RealAmount)))
adocmd.Parameters.Item(1).Value = strUnitCN
adocmd.Parameters.Item(2).Value = strUnitEN
adocmd.Parameters.Item(3).Value = CSng(Val(.TextMatrix(intRow, DNModify.Amount)))
adocmd.Parameters.Item(4).Value = DNString
adocmd.Parameters.Item(5).Value = .TextMatrix(intRow, DNModify.JDE_Code)
adocmd.Parameters.Item(6).Value = CInt(.TextMatrix(intRow, DNModify.Sequency))
adocmd.Execute
单引号,咋就无法执行了?数据中包含单引号?如果不是数据包含,使用:sql="select * from table1 where username='" & text1.text & "'"
dim strA() as string
strA = Split(txtUsername.Text, "'") '如果含有"'"就会把字符串截开,赋值到数组
If UBound(strA) <> 0 Then
MsgBox "用户名中有非法字符,请重新输入!", vbOKOnly + vbExclamation, "警告"
Exit Sub
End If
'限制输入非法字符
dim bJudge as boolean
bJudge = txtUserID Like "*'*"
If bJudge Then
MsgBox "请不要输入非法字符!", vbOKOnly + vbExclamation, "警告"
End If
End Sub
如果是为了防止Text1中包含',可以使用以下语法,将'过滤掉
sql="select * from table1 where username='" &amp; Replace(text1.text,"'","")……
过滤掉的话就不是原来的text了,还是提示从新输入吧