小弟期末设计做数据库,用VB做界面什么的
现在要实现查询的功能,找了一个书上的例子是
“Dim str As String
Dim mybook As Variant
mybook = Adodc1.Recordset.Book
str = "姓名= ' " & "Text2.Text & " '"
Adodc1.Recordset.MoveFirst
Adodc1.Recordset.Find str
If Adodc1.Recordset.EOF Then
MsgBox "指定条件没有匹配结果"
Adodc1.Recordset.Book = mybook
End If

但是代码输入以后是这样红圈处符号是绿色的,也就是说,'" 因为VB的 ' 被忽略了,现在该怎么办?

解决方案 »

  1.   

    str = "姓名= ' " & "Text2.Text & " '"
    =>
    str = "姓名= ' " & Text2.Text & " '"
      

  2.   

    不是的,在成对的双引号中间的 ' 不会被当作注释标记。str = "姓名= ' " & "Text2.Text & " '"多了一个双引号。strPatern = "姓名='" & Text2.Text & "'"
    Adodc1.Recordset.MoveFirst
    Adodc1.Recordset.Find strPatern
    另外,你看的什么书,如此不规范。Str 是 VB 关键字(内部函数名),不要用 str 这样的变量名。虽然可用,但这是不好的编程习惯。