Question:
In Visual Basic, is it possible to search a database for any results CONTAINING a keyword from a textbox?
Ryan
2012-05-22 10:24:47 UTC
For example:

I have a database with two items in it. Those items could be "Sky", and "Ski", for example.

I have a textbox with a "Filter" button beside it. When the button is pressed, I would like for the database grid view to show ALL results that CONTAIN the word(s) in the textbox.

Let's say I type "Sk" in the text box. I would like both "Sky" AND "Ski" to be displayed, because they both contain the "Sk" that was typed in the text box. Of course, if I type "Sky" in the text box, only "Sky" should be displayed in the grid view of the database.

I have not been able to find a good, simple way to do this, and I know there must be one out there.

Example code:

The code that I am using is as follows (this one is just an example):

Me.ExampleCodeBindingSource.Filter = "ItemName = '" & Me.TextBox1.Text & " ' "

This code ONLY displays results in the grid view that match EXACTLY what is in the textbox. Any thoughts on how to find results that CONTAIN the textbox word(s) in them?

Thanks!
Three answers:
anonymous
2016-10-16 18:29:21 UTC
why to ascertain the entered sort each time the textual content textile is replaced? why to no longer ascertain the fee of the textbox while the type is submitted as an occasion?i recommend the respond relies upon rather on the way your sort is equipped , if the consumer enters a sort (shall we are saying decimals or int) isnt there some thing like 'shop' button , or 'upload checklist' or in spite of ? if specific , while the consumer clicks the placed up button , u examine if values are valid , if no longer , reveal a message field exhibiting the errors and ask the consumer to insert 'valid' values..
Tony C
2012-05-22 15:39:35 UTC
instead of using =, use LIKE and the % wildcard. Try this.



Me.ExampleCodeBindingSource.Filter = "ItemName LIKE '%" & Me.TextBox1.Text & "%'"



The % wildcard means any character (zero or more characters) before and after the text.
anonymous
2012-05-23 01:43:48 UTC
try this

Dim Search As String

Search = "Sk"

Set RECTGL = New ADODB.Recordset

RECTGL.Open "Select distinct TANGGAL From HISTORY WHERE TANGGAL like '" & Search & "%'", CN, adOpenDynamic, adLockOptimistic


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...