首页上一页 1 下一页尾页 1 条记录 1/1页
请帮忙修改一下
发表在VB答疑区
2009-10-07
是否精华
是
否
版块置顶:
是
否
我写了代码,想实现查询功能,就是通过text1中的用户名称,通过点击“查询”,用户的其它信息分别在text2\text3等中显示出来,但我调试总是出错,能不能帮我改改:代码如下:
Dim cnn As New Adodb.Connection
Dim rs As New Recordset
Private Sub Command4_Click()
rs.Filter = " 用户名称 like'" + "*" + Trim(Text1.Text) + "*" '"
ViewData
End Sub
Private Sub ViewData() '定义显示数据的过程
On Error Resume Next
With rs
Text2.Text = .Fields("用户号")
Text3.Text = .Fields("用电地址")
Text4.Text = .Fields("接电日期")
Text5.Text = .Fields("联系人")
Text6.Text = .Fields("联系电话")
Text7.Text = .Fields("计量方式")
Text8.Text = .Fields("用电性质")
End With
End Sub
Private Sub Command1_Click()
Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields("用户名称") = Text1
Adodc1.Recordset.Fields("用户号") = Text2
Adodc1.Recordset.Fields("用电地址") = Text3
Adodc1.Recordset.Fields("接电日期") = Text4
Adodc1.Recordset.Fields("联系人") = Text5
Adodc1.Recordset.Fields("联系电话") = Text6
Adodc1.Recordset.Fields("计量方式") = Text7
Adodc1.Recordset.Fields("用电性质") = Text8
End Sub
Private Sub Command2_Click()
Adodc1.Recordset.Delete
Adodc1.Recordset.Update
End Sub
Private Sub Command3_Click()
Adodc1.Refresh
End Sub
Private Sub Form_Load()
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\My Documents\客户信息登记表.mdb;Persist Security Info=False"
rs.Open "select * from 客户信息", cnn, adOpenKeyset, adLockOptimistic
ViewData
End Sub
Dim cnn As New Adodb.Connection
Dim rs As New Recordset
Private Sub Command4_Click()
rs.Filter = " 用户名称 like'" + "*" + Trim(Text1.Text) + "*" '"
ViewData
End Sub
Private Sub ViewData() '定义显示数据的过程
On Error Resume Next
With rs
Text2.Text = .Fields("用户号")
Text3.Text = .Fields("用电地址")
Text4.Text = .Fields("接电日期")
Text5.Text = .Fields("联系人")
Text6.Text = .Fields("联系电话")
Text7.Text = .Fields("计量方式")
Text8.Text = .Fields("用电性质")
End With
End Sub
Private Sub Command1_Click()
Adodc1.Recordset.AddNew
Adodc1.Recordset.Fields("用户名称") = Text1
Adodc1.Recordset.Fields("用户号") = Text2
Adodc1.Recordset.Fields("用电地址") = Text3
Adodc1.Recordset.Fields("接电日期") = Text4
Adodc1.Recordset.Fields("联系人") = Text5
Adodc1.Recordset.Fields("联系电话") = Text6
Adodc1.Recordset.Fields("计量方式") = Text7
Adodc1.Recordset.Fields("用电性质") = Text8
End Sub
Private Sub Command2_Click()
Adodc1.Recordset.Delete
Adodc1.Recordset.Update
End Sub
Private Sub Command3_Click()
Adodc1.Refresh
End Sub
Private Sub Form_Load()
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\My Documents\客户信息登记表.mdb;Persist Security Info=False"
rs.Open "select * from 客户信息", cnn, adOpenKeyset, adLockOptimistic
ViewData
End Sub