创建搜索栏 [英] Creating a search bar

查看:94
本文介绍了创建搜索栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作搜索栏。到目前为止,如果我输入我想要搜索的信息的确切单词,这段代码就可以工作了,但我想要做的是至少检测我在搜索栏中输入的8-10个字符,结果会显示



另外.. 我在搜索数字数据类型时遇到问题。它不会让我用数字搜索信息。只有文字..



知道为什么吗?



I am trying to make a search bar. So far this code works if I type the exact words of the information I want to search, but what I want to do is to at least detect 8-10 characters from what I typed in the search bar and the results would show.

Also.. I am having problems when searching for number data types. It won''t let me search information with numbers in it. Only texts..

Any idea why?

connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\lppUni.mdb;"
       Dim ds As New DataSet
       Dim sql As String = "Select * from LPPUN where studID = '" & TextBox1.Text & "' OR studName = '" & TextBox1.Text & "' OR studCourse = '" & TextBox1.Text & "'"
       Dim dt As DataTable
       cnn = New OleDbConnection(connectionString)

       Try
           cnn.Open()
           adptr = New OleDbDataAdapter(sql, cnn)
           adptr.Fill(ds)
           adptr.Dispose()
           cnn.Close()

           dt = ds.Tables(0)
           studformGridView.DataSource = dt
       Catch ex As Exception
           MsgBox(ex.ToString)
       End Try

       studformGridView.Visible = True
   End Sub

推荐答案

使用Like代替=



从LPPUN中选择*其中studID喜欢''%'&TextBox1.Text +%''或studName喜欢''%'&TextBox1.Text +% ''或者studCourse赞''%'&TextBox1.Text +%''



,你的搜索将返回匹配的字符。
Use Like in place of =

"Select * from LPPUN where studID Like ''%" & TextBox1.Text +"%'' OR studName Like ''%" & TextBox1.Text + "%'' OR studCourse Like ''%" & TextBox1.Text + "%''"

and your search will return with matching characther.


与上一个解决方案一样,使用喜欢,但也可以用&更改+



例如



从LPPUN中选择*其中studID喜欢''%'&TextBox1.Text&%''或studName喜欢''%'&TextBox1.Text&%''或者studCourse赞' '%'&TextBox1.Text&%''



另外,请注意文本框值的有意/无意SQL注入



: - )
As with the prev Solution, use "like" but also change the "+" with "&"

e.g.

"Select * from LPPUN where studID Like ''%" & TextBox1.Text & "%'' OR studName Like ''%" & TextBox1.Text & "%'' OR studCourse Like ''%" & TextBox1.Text & "%''"

Also, watch out for intentional / non-intentional SQL injection with your textbox values

:-)


这篇关于创建搜索栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆