In Visual Basic, is it possible to search a database for any results CONTAINING a keyword from a textbox?
-
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!
-
Answer:
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
Ryan at Yahoo! Answers Visit the source
Other answers
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.
Related Q & A:
- Is it possible to allow a client/user to log into a Remote Desktop session using credentials other than their AD username/password? (for SSO?Best solution by Server Fault
- Is it possible to become a neonatal nurse as well as a pediatric nurse?Best solution by netpediatrics.com
- How to get a new title when you buy a car from a private seller?Best solution by dol.wa.gov
- Codes for a simple visual basic program.Best solution by vbtutor.net
- Is java or visual basic a machine level, low level, high level or binary level programming language?Best solution by Quora
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.