Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
When i excute this query it works if am searching for `tbl_permits`.`bid` BUT when i use tbl_permits`.`company` it says Unknown column "whatever i was searching comes here in this qoutes"
"SELECT * FROM `tbl_permits` WHERE `tbl_permits`.`bid`=" & txtSearch.Text & " OR `tbl_permits`.`company`=" & txtSearch.Text & ";"


thanks in advance
Posted

I am not sure why you put the table name and column names in single quote.
Try:
SQL
"SELECT * FROM tbl_permits WHERE tbl_permits.bid='" & txtSearch.Text & "' OR tbl_permits.company='" & txtSearch.Text & "'"


You were missing the single quotes around the searchtext values passed to query.

Further, I would suggest you to use 'parametrized query'. It will overcome lots of issues and is much cleaner and safer way to execute queries.

UPDATE: You should use parameterized query[^] with your command.
 
Share this answer
 
v2
Comments
Kim Togo 25-May-11 5:12am    
Good answer about parametrized query, my 5.
joseph k 25-May-11 5:32am    
Tell me about parametrized query. Where to start...
Sandeep Mewara 25-May-11 5:50am    
Answer updated to start with.
joseph k 25-May-11 8:01am    
You meant "Stored Procedures"?
Sandeep Mewara 25-May-11 9:43am    
No. Stored Procedure is different. I meant Parameterized query only. If needed, just Google the magic words and see (In case you did not get from the link I shared.)
You can also use like this


"SELECT * FROM tbl_permits WHERE bid='" & txtSearch.Text & "' OR company='" & txtSearch.Text & "'"
 
Share this answer
 
Comments
fjdiewornncalwe 25-May-11 9:39am    
Injection attack waiting to happen here, but the answer is still valid within the scope of the question. I'm just commenting to add a little more support to the parameterized query suggested by Sandeep.
joseph k 27-May-11 3:29am    
Thanks , working on all options

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900