我写了一段代码,但是似乎是SQL语句出了问题,在VisData中无法执行正确的结果。请大家看看,模糊查询是怎么写的?谢谢!
Private Sub cmdSeek_Click()
Dim stname As String, conn as new adodb.connection
Dim rst As New ADODB.Recordset, sqlseek As String
Dim strCnn As String
strCnn = "Provider=Microsoft.Jet.OLEDB.3.51;Persist Security Info=False;Data Source=D:\VBPractice\VB过关\a.mdb"
conn.Open strCnn
stname = InputBox("请输入要查询的学生姓名,可进行模糊查询:", "查询")
sqlseek = "select * from student where name like '*" & stname & "*'"
rst.Open sqlseek, conn, adOpenKeyset, adLockOptimistic
Adodc1.RecordSource = sqlseek
Adodc1.Refresh
DataGrid1.ReBind
If rst.EOF = True Then
Adodc1.RecordSource = sqlseek
Adodc1.Refresh
DataGrid1.ReBind
MsgBox "没找到此学生!", vbOKOnly, "注意"
rst.Close
Exit Sub
End If
rst.Close
conn.Close
End Sub