怎么写VB用Ado查询数据

yeruping 2008-11-28 08:59:26
功能:点查找按钮,跳出一个输入框,输入要查找的内容
然后怎么写VB用Ado查询数据并且把这查出的记录显示到相应的文本框中

因为一个小系统要用到VB,以前只开过些课
现在什么都忘记了..
希望可以写出全过程

谢谢大家
...全文
221 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
jhone99 2008-11-28
  • 打赏
  • 举报
回复
Private Sub Command4_Click()
Dim i As Integer
Dim strCustID As String
Dim blnHave As Boolean

strCustID = InputBox("please input want query")

If strCustID <> "" Then

With Adodc1
.Recordset.MoveFirst

For i = 1 To .Recordset.RecordCount
If .Recordset.Fields("供应商号") & "" = strCustID Then
Exit For
blnHave = True
End If

.Recordset.MoveNext
Next i

If blnHave Then
MsgBox "有相关记录"
Else
MsgBox "没有相关记录"
End If
End With
Else
MsgBox "没有输入任何信息"
End If


End Sub
yeruping 2008-11-28
  • 打赏
  • 举报
回复


Private Sub Command1_Click()
Me.Hide
Form3.Show
Form3.Text1.Text = Form2.Text1.Text
Form3.Text2.Text = Form2.Text2.Text
Form3.Text3.Text = Form2.Text3.Text
Form3.Text4.Text = Form2.Text4.Text
Form3.Text5.Text = Form2.Text5.Text
Form3.Command3.Visible = False
End Sub

Private Sub Command2_Click()
Unload Me
Form3.Show
Form3.Command1.Visible = False
End Sub

Private Sub Command3_Click()
If MsgBox("确定要删除本信息吗", vbQuestion + vbYesNo, "敬告") = vbYes Then
Adodc1.Recordset.Delete
Adodc1.Recordset.MoveNext
End If
End Sub

Private Sub Command4_Click()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim strSql As String
Dim strName As String
cn.CursorLocation = adUseClient
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\商品管理.mdb;Persist Security Info=False"
strName = InputBox("please input want query")

If strName <> "" Then
rs.Open "select * from 供应商信息 where 供应商号=" & strName & " ", cn, adOpenStatic, adLockOptimistic


If rs.RecordCount > 0 Then
Text1.Text = rs.Fields("供应商号") & ""
Text2.Text = rs.Fields("供应商名") & ""
Text3.Text = rs.Fields("地址") & ""
Text4.Text = rs.Fields("联系电话") & ""
Text5.Text = rs.Fields("银行账户") & ""
Else
MsgBox "没有相关记录"
End If

rs.Close
Set rs = Nothing
Else
MsgBox "没有输入任何信息"
End If

cn.Close
Set cn = Nothing

End Sub

Private Sub Command5_Click()
Adodc1.Recordset.MoveFirst
End Sub

Private Sub Command6_Click()
Adodc1.Recordset.MovePrevious
If Adodc1.Recordset.BOF Then
Adodc1.Recordset.MoveFirst
Command6.Enabled = False
End If
End Sub

Private Sub Command7_Click()
Adodc1.Recordset.MoveNext
If Adodc1.Recordset.EOF Then
Adodc1.Recordset.MoveLast
Command7.Enabled = False
End If
End Sub

Private Sub Command8_Click()
Adodc1.Recordset.MoveLast
End Sub

Private Sub Command9_Click()
Unload Me
Form4.Show
End Sub

Private Sub Text1_Change()
If Command6.Enabled = False Or Command7.Enabled = False Then
Command6.Enabled = True
Command7.Enabled = True
End If
End Sub


yeruping 2008-11-28
  • 打赏
  • 举报
回复
谢谢啊 查找是可以了 但查找后点上一条 下一条时就出错了,
要是没找查的话,就不会出错
这是怎么搞得?
northwolves 2008-11-28
  • 打赏
  • 举报
回复
Private Sub Command1_Click()
With CreateObject("ADODB.Connection")
.Open Yourcnstring'Write you connection string here.
Text1.Text = .Execute("select field1 from table").getstring()'Get all field1 from table
.Close
End With
End Sub
jhone99 2008-11-28
  • 打赏
  • 举报
回复
Private Sub Command1_Click()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim strSql As String
Dim strName As String

cn.CursorLocation = adUseClient
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\mydb.mdb;Persist Security Info=False"

strName = InputBox("please input want query")

If strName <> "" Then
rs.Open "select * from mytable where id='" & strName & "' ", cn, adOpenStatic, adLockOptimistic


If rs.RecordCount > 0 Then
Text1.Text = rs.Fields("id") & ""

MsgBox "have"
Else
MsgBox "not have"
End If

rs.Close
Set rs = Nothing
Else
MsgBox "no input"
End If

cn.Close
Set cn = Nothing

End Sub

7,765

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧