943,936 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Unsolved
  • Views: 499
  • VB.NET RSS
Nov 6th, 2009
0

Issue using Like in VB query to Access DB

Expand Post »
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

VB.NET Syntax (Toggle Plain Text)
  1. 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
Reputation Points: 10
Solved Threads: 0
Light Poster
Loony064 is offline Offline
37 posts
since Sep 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Protect Sheet with VBA
Next Thread in VB.NET Forum Timeline: Can I have a message box pop up in a form that is called via ShowDialog?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC