视觉基本像错误

时间:2017-05-16 16:48:51

标签: sql vb6 sql-like clause

Private Sub txtmid_Change()
On Error Resume Next

Mmid = txtmid.Text

Adodc1.RecordSource = "select * from members where txtmid like '" & Mmid & "'"
Adodc1.Refresh

Mname = Adodc1.Recordset.Fields("Mname").Value
Expiryd = Adodc1.Recordset.Fields("Expiryd").Value

txtname.Text = Mname
txtedate(1).Text = Format(Expiryd, "dd / mm / yyyy")
End Sub

我收到FROM子句错误。请帮我解决这个错误。谢谢。

1 个答案:

答案 0 :(得分:0)

试试这个:

首先,删除On Error Resume Next,因为它很危险(您应该使用非常错误处理程序)。

Adodc1.RecordSource = "select * from members where Mmid = '" & Mmid & "'"

注意:无论如何,对于TEXT类型的字段,您应该始终使用Replace $()替换'double quote'以避免在字符串值包含单引号时出错。例如:

Dim sql As String
Dim sSearch As String
sSearch = "You are 'magic' developer"
sql = "SELECT * FROM Users WHERE Note = '" & Replace$(sSearch, "'", "''") & "'"

否则,在这种情况下,如果您使用(错误地):

sql = "SELECT * FROM Users WHERE Note = '" & sSearch & "'"

您将收到错误。