| | |
Issue using Like in VB query to Access DB
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
Hi Everyone
I'm designing a program with a front end vb.net (2007 Express version) app and a back-end Access 2007 database. I've added the following query to the database dataset (SAUJSDataSet). I have a table which contains information of students and there is a search form where the user can input a variety of search parameters depending on how specific they want their search to be. I used the following query
The query is called as follows when the search button is pressed, where fname, lname, tel, cell, email, univ and degree are variables storing the relevant search criteria.
Me.StudentsTableAdapter.FillBySearchStudentG(SaujsDataSet.Students, fname, lname, tel, cell, email, univ, degree)
It works fine if all the fields in the table that are searched have a value in it (i.e, so long as each record has a first name, last name, telnum, celnum, email, university and degree) but the moment one of those fields is blank in the database (e.g. the person doesn't have an email address) it won't include that record in the results even if no email address is entered in the search parameters and the record matches all other search criteria.
How can i modify my code so that it will return records with no data in specific fields so long as there is nothing specified in that field in the search criteria (e.g. search for FirstName = "Sar", LastName = "Sm", telnum, celnum, email, university and degree are left blank, should return the record with FirstName = "Sarah", LastName = "Smith", telnum ="1234567890", celnum = "0987654321", email = "", ... and so on
I hope i've made some sense with what I'm trying to ask. I'd appreciate any help with this.
Thanks
Laura
I'm designing a program with a front end vb.net (2007 Express version) app and a back-end Access 2007 database. I've added the following query to the database dataset (SAUJSDataSet). I have a table which contains information of students and there is a search form where the user can input a variety of search parameters depending on how specific they want their search to be. I used the following query
VB.NET Syntax (Toggle Plain Text)
SELECT * FROM Students WHERE (FirstName LIKE '%' + ? + '%') AND (LastName LIKE '%' + ? + '%') AND (TelNum LIKE '%' + ? + '%') AND (CelNum LIKE '%' + ? + '%') AND (Email LIKE '%' + ? + '%') AND (University LIKE '%' + ? + '%') AND (Degree LIKE '%' + ? + '%')
The query is called as follows when the search button is pressed, where fname, lname, tel, cell, email, univ and degree are variables storing the relevant search criteria.
Me.StudentsTableAdapter.FillBySearchStudentG(SaujsDataSet.Students, fname, lname, tel, cell, email, univ, degree)
It works fine if all the fields in the table that are searched have a value in it (i.e, so long as each record has a first name, last name, telnum, celnum, email, university and degree) but the moment one of those fields is blank in the database (e.g. the person doesn't have an email address) it won't include that record in the results even if no email address is entered in the search parameters and the record matches all other search criteria.
How can i modify my code so that it will return records with no data in specific fields so long as there is nothing specified in that field in the search criteria (e.g. search for FirstName = "Sar", LastName = "Sm", telnum, celnum, email, university and degree are left blank, should return the record with FirstName = "Sarah", LastName = "Smith", telnum ="1234567890", celnum = "0987654321", email = "", ... and so on
I hope i've made some sense with what I'm trying to ask. I'd appreciate any help with this.
Thanks
Laura
![]() |
Similar Threads
- sql query problem with MS Access and C# (C#)
- Query Criteria issue and Emailing with Access 07 (MS Access and FileMaker Pro)
- Query Column names with spaces in MS ACCESS using Python (Python)
- macro using microsoft query and access (Visual Basic 4 / 5 / 6)
- Saving Query in Ms Access .MDb File using C++ (C++)
- Not able to save query in access (IT Professionals' Lounge)
- i want to save a query in MS Access Database throug c# coding (C#)
- create a query in access from vb6 (Visual Basic 4 / 5 / 6)
- Access XP Crashes at Query Run (MS Access and FileMaker Pro)
Other Threads in the VB.NET Forum
- Previous Thread: Protect Sheet with VBA
- Next Thread: Can I have a message box pop up in a form that is called via ShowDialog?
| Thread Tools | Search this Thread |
"crystal .net .net2005 30minutes 2008 access add application arithmetic array assignment basic binary box button buttons center click code combo combobox component connectionstring convert cpu data database databasesearch datagrid datagridview design dissertation dissertations dissertationthesis dosconsolevb.net editvb.net employees excel exists firewall folder image images isnumericfuntioncall login math memory mobile module ms msaccess mssqlbackend mysql navigate net opacity pan peertopeervideostreaming picturebox picturebox1 port print printpreview problemwithinstallation project record regex reports" reuse right-to-left save savedialog search serial sorting sqldatbase storedprocedure string temp textbox timer txttoxmlconverter updown useraccounts usercontol usercontrol vb vb.net vb.netcode vb.nettoolboxvisualbasic2008sidebar vbnet view vista visual visualbasic visualbasic.net visualstudio web wpf xml





