vb Set rst = con.Execute("select * from 用户信息 where 姓名 like '" & Text1.Text & "'")类型不匹配

来源:百度知道 编辑:UC知道 时间:2024/05/26 04:37:30
Private Sub Command1_Click()
Dim rst As Recordset
Dim con As New ADODB.Connection
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\用户信息\用户信息.mdb;Persist Security Info=False"
con.Open
Set rst = con.Execute("select * from 用户信息 where 姓名 like '" & Text1.Text & "'")

If Not rst.EOF Then
con.Execute "update from 用户信息 where 密码 like '" & Text2.Text & "'"
MsgBox "修改成功!"
Adodc1.Refresh
Adodc1.Recordset.Update
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
End If
End Sub

为什么这段代码老提示我类型不匹配~谁能帮忙解答一下吗

给我邮箱 我发给你QQ892113807

1. Dim rst As Recordset 改成 Dim New rst As ADODB.Recordset
2. Set rst = con.Execute("select * from 用户信息 where 姓名 like '" & Text1.Text & "'") 改成 Set rst = con.Execute("select * from 用户信息 where 姓名 like " & "'%" & Text1.Text & "%'" )

Like须和"%"一起使用

---------------------------

完整的代码

Private Sub Command1_Click()
Dim rst As New ADODB.Recordset
Dim con As New ADODB.Connection
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\用户信息\用户信息.mdb;Persist Security Info=False"
con.Open
Set rst = con.Execute("select * from 用户信息 where 姓名 like '%" & Text1.Text & "%'")

If Not rst.EOF Then
con.Execute "update from 用户信息 where 密码 like '%" & Text2.Text & "%'"
MsgBox "修改成功!"
Adodc1.Refresh
Adodc1.Re