This code below is were my main seach function is. The problem is that i can't add more tables to make it search. It is only working with one table.
SQL= "SELECT * from mydatabase where id like '%" & search.Text & "%'"
What i want is something like this:
SQL= "SELECT * from mydatabase where id, name, lastname like '%" & search.Text & "%'"
I have tried diffrent types of code to make it happend, but there was no success.
You coure use OR condicions:
SQL= "SELECT * from mydatabase
where id like '%" & search.Text &"%"
Or name like '%" & search.Text &"%"
Or lastname like '%" & search.Text & "%'"
Related
I was wondering if someone could help me with this. I have a form in Access that has a combo box to look up an item number. Right now the Row Source is something like
Select ItemCode, ItemDescription From MyTable Where ItemType = 'G'
I would like to change it to allow a wild card. So right now if you type in C* it will not work. How do I make that work? Do I just update it to say
Select ItemCode From MyTable Where ItemType = 'G'
or is there more to it?
It's calling a query which is calling a SQL database. It's passing parameters like the date and itemcode.
It's calling a pass-through query to the database That looks like this...
pt_JobAnalysis '12/26/2017' , '01/26/2018' , '' , '10516' , ''
sSQL = sProcedureName & " '" & Me.txtFrom & "' , '" & Me.txtTo & "'"
Thank you so much.
Something like this should do it:
"Like '*'"
OR . . .
If IsNull(Me.txtFirstName.Value) Then
strFirstName = "Like '*'"
Else
SelectCase Me.fraFirstName.Value
Case 1
strFirstName = "Like '" & Me.txtFirstName.Value & "*'"
Case 2
strFirstName = "Like '*" & Me.txtFirstName.Value & "*'"
Case 3
strFirstName = "Like '*" & Me.txtFirstName.Value & "'"
Case 4
strFirstName = "= '" & Me.txtFirstName.Value & "'"
End Select
End If
FINALLY . . .
The link below should help you a lot!
https://www.fontstuff.com/access/acctut19.htm
i have a vb.net application with MySQL i want to search the db and filter the results using Combobox and textbox
SQL = "select * FROM duty where '" & ComboBox3.Text & "' = '" & TextBox15.Text & "' "
If you are searching for a string, use a LIKE keyword on your SELECT statement.
Example:
SQL = "SELECT * FROM duty WHERE '" & ComboBox3.Text & "' LIKE '" & TextBox15.Text & "%';"
Aside from the SQL injection issues,
Add % wildcard.
SQL = "select * FROM duty where '" & ComboBox3.Text & "' = '%" & TextBox15.Text & "%' "
This is my query with 2 parameters. Can someone please help me?
sql = "select *
from studentlist
where firstname like '%"
& Transaction.SEARCHSTUDENT.Text
& "%' or studentnum like '%"
& Transaction.SEARCHSTUDENT.Text
& "%' and not in (select studentnum from borrowing of books where status ='borrowed')"
If borrowing of books is your table name (with whitespaces) it should be enclosed with backticks like so:
`borrowing of books`
Edit: Also, it looks like studentnum is missing in your where clause, so it should actually look like this:
sql = "select *
from studentlist
where (firstname like '%"
& Transaction.SEARCHSTUDENT.Text
& "%' or studentnum like '%"
& Transaction.SEARCHSTUDENT.Text
& "%') and studentnum not in (select studentnum from `borrowing of books` where status ='borrowed')"
Currently am using the following code for search for a word in the entire table,
Dim searchKey As String = "Sample"
Dim mysql As String = "SELECT * FROM myTable " & _
"WHERE col1 LIKE '%" & searchKey & "%' " & _
" OR col2 LIKE '%" & searchKey & "%' " & _
" OR col3 LIKE '%" & searchKey & "%' " & _
" OR col4 LIKE '%" & searchKey & "%' "
But querying became more difficult when the number of column increases. so can anyone suggest me some alternative method for do the same.
use a loop to build your String programmatically .in this example you only need to add your columns to array.
Dim searchKey As String = "Sample"
Dim array() As String = {"col1", "col2", "col3", "col4"}
Dim b As Boolean = True
Dim mysql As String = "SELECT * FROM myTable WHERE "
For Each str As String In array
If b Then
mysql = mysql & str + " LIKE '%" & searchKey & "%'"
Else
mysql = mysql & " OR " & str & " LIKE '%" & searchKey & "%'"
End If
b = False
Next
Debug.WriteLine(mysql)
output>>
SELECT * FROM myTable WHERE col1 LIKE '%Sample%' OR col2 LIKE '%Sample%' OR col3 LIKE '%Sample%' OR col4 LIKE '%Sample%'
You can also take help of the fulltext search provided by MySQL.
This link provides details on fulltext search, http://dev.mysql.com/doc/refman/5.0/en/fulltext-natural-language.html
You can do something like this, If there is change in table structure then you need to add/remove columns from the query.
SELECT * FROM myTable WHERE Concat(col1, '',col2, '', coln) LIKE '%searchKey%'
i have this search function to search for Firstname Middlename individually with their own CheckBox, this thing came to my mind if i want to search for Firstname and Middlename together in one Textbox with space of course and tried to use SELECT statement with CONCAT, but it didn't work.
it looks like this one:
If CheckBox1.Checked And CheckBox2.Checked Then
SQL = "SELECT * from student where CONCAT(fname,"" "", mname) like '%" & TextBox1.Text & "%'"
End if
Try this:
If CheckBox1.Checked And CheckBox2.Checked Then
SQL = "SELECT * from student where CONCAT(fname,' ', mname) like '%" & TextBox1.Text & "%'"
End if
EDIT
SELECT * FROM student WHERE MATCH (fname, mname) AGAINST ('+" & TextBox1.Text & "* +" & TextBox1.Text & "*' IN BOOLEAN MODE)
Might be this will give you the desired result