有关SQL语句的问题

来源:百度知道 编辑:UC知道 时间:2024/07/04 17:46:14
Dim mysql As String
If Text1.text <> "" Then
mysql = "'姓名 like '" & Text1.text
End If
If Text2.text <> "" Then
If mysql <> "" Then
mysql = mysql & "'电话 like'" & Text2.text
Else
mysql = "'电话 like '& text2.text"
End If
End If
Adodc1.RecordSource = "select * from 我的通讯录 where" & "'" & mysql & "'"
我的刚学的,高手能否帮我看一下错在哪儿了?
谢谢您了

说实话,错的地方挺多的,帮你改了一下,你对比一下哪个地方有问题吧。

Dim mysql As String
If Text1.text <> "" Then
mysql = "姓名 like '%" & Text1.text "%'"
End If
If Text2.text <> "" Then
If mysql <> "" Then
mysql = mysql & "and 电话 like '%" & Text2.text & "%'"
Else
mysql = "电话 like '%" & text2.text & "%'"
End If
End If
Adodc1.RecordSource = "select * from 我的通讯录 where " & mysql & ""

Text1.text <> "" Then
mysql = "姓名 like '%" & Text1.text & "%'"
End If
If Text2.text <> "" Then
If mysql <> "" Then
mysql = mysql & " and 电话 like'%" & Text2.text & "%'"
Else
mysql = "电话 like '& text2.text" & "%'"
End If
End If