当前位置:编程学习 > VB >>

如何编写一个简单的从数据库中搜索的功能?

我现在有一个名为db1.mdb的Access数据库,里面笔记本表格里有一个型号的字段,我现在想实现一个由text1中输入的的关键字,完后点一下cmd1,就在数据库中搜索,并且在text2中输出搜索到的那个结果,请问这个功能该怎么实现?万分感谢!! --------------------编程问答-------------------- strsql="select pc_type from pc_ref where pc_type like '" & text1.text & "%' " --------------------编程问答--------------------
引用 1 楼 jhone99 的回复:
strsql="select pc_type from pc_ref where pc_type like '" & text1.text & "%' "


您要,用中文的“型号”和“笔记本”不行么? --------------------编程问答--------------------
引用 2 楼 raikecody 的回复:
引用 1 楼 jhone99 的回复:

strsql="select pc_type from pc_ref where pc_type like '" & text1.text & "%' "


您要,用中文的“型号”和“笔记本”不行么?


可以,但最好加[] --------------------编程问答-------------------- strsql="select [型号] from [笔记本] where [型号] like '" & text1.text & "%' "
--------------------编程问答--------------------
引用 3 楼 jhone99 的回复:
引用 2 楼 raikecody 的回复:
引用 1 楼 jhone99 的回复:

strsql="select pc_type from pc_ref where pc_type like '" & text1.text & "%' "


您要,用中文的“型号”和“笔记本”不行么?


可以,但最好加[]

哦,好,那我怎么让他在text2里输出搜索结果呢?还有只要这一行代码就可以实现了吗? --------------------编程问答-------------------- --------------------编程问答-------------------- 加三个控件

两个textbox,一个commandbutton

*********************************
引用
microsoft activex data objects 2.8 library --------------------编程问答--------------------
Private Sub Command1_Click()
    Dim cn As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    Dim strSql As String
    
    cn.CursorLocation = adUseClient
    cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\tt\mm\db1.mdb;Persist Security Info=False"
    
    strSql = "select [型号] from [笔记本] where [型号] like '%" & Text1.Text & "%' "

    rs.Open strSql, cn, adOpenStatic, adLockOptimistic
    
    If rs.RecordCount > 0 Then
        Text2.Text = rs.Fields(0)
    End If
    
    rs.Close
    Set rs = Nothing
    cn.Close
    Set cn = Nothing
End Sub
--------------------编程问答-------------------- 使用模糊查询,将满足条件的数据取出来,然后使用Grid之类的控件加以显示就完了. --------------------编程问答-------------------- 使用Select配合Like语句实现模糊查询。
http://download.csdn.net/source/1644211 --------------------编程问答-------------------- 使用Select配合Like语句实现模糊查询。
http://download.csdn.net/source/1644211
补充:VB ,  数据库(包含打印,安装,报表)
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,