Results from Select statement differ in VB.NET and Access

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2006
Posts: 3
Reputation: pclpossum is an unknown quantity at this point 
Solved Threads: 0
pclpossum pclpossum is offline Offline
Newbie Poster

Results from Select statement differ in VB.NET and Access

 
0
  #1
Sep 23rd, 2006
Hello!

I have an SQL query designed to search a string field and return results based on input from the user.

If I use VB.NET to interrogate the Access Db using the following SQL:

"Select *FROM TRAINING WHERE ((Trainer Like '*Rob*'));"

I get no results.

If I perform this same query directly in the DB (eg in Access iteslf) I get a number of hits (which are correct).

The code I'm using to create the connection etc is:
  1. Dim adapter As OleDb.OleDbDataAdapter
  2. Dim Connection As OleDb.OleDbConnection
  3.  
  4. searchResults = New DataSet
  5.  
  6. Connection = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Trainers.mdb")
  7. adapter = New OleDb.OleDbDataAdapter(searchText, Connection)
  8. adapter.Fill(searchResults)
  9.  
  10. Connection.Close()
  11.  
  12. ' Where searchText =
  13. ' "Select * FROM TRAINING WHERE (( Trainer Like '*Rob*'));"

(searchResults is defined as a DataSet outside of this procedure)

This code and the way I'm creating the query works for every other search I perform.

I'm not sure if its the version of VB Express/MS Access I'm using, or if I'm missing something simple.

Any help would be greatfully recieved.

Cheers
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 1
Reputation: sahra is an unknown quantity at this point 
Solved Threads: 0
sahra sahra is offline Offline
Newbie Poster

Re: Results from Select statement differ in VB.NET and Access

 
0
  #2
Sep 23rd, 2006
Dear

use this code to connect to the Access database:
Private Const CONNSTR As String = "Provider=Microsoft.Jet.OLEDB.4.0;Password="""";" & _
"User ID=Admin;" & _
"Data Source=Trainers.mdb;" & _
"Mode=Share Deny None;Extended Properties="""";" & _
"Jet OLEDBystem database="""";" & _
"Jet OLEDB:Registry Path="""";" & _
"Jet OLEDB: Database Password="""";" & _
"Jet OLEDB:Engine Type=5;" & _
"Jet OLEDB: Database Locking Mode=1;" & _
"Jet OLEDB:Global Partial Bulk Ops=2;" & _
"Jet OLEDB:Global Bulk Transactions=1;" & _
"Jet OLEDB:New Database Password="""";" & _
"Jet OLEDB:Create System Database=False;" & _
"Jet OLEDB:Encrypt Database=False;" & _
"Jet OLEDB: Don't Copy Locale on Compact=False;" & _
"Jet OLEDB:Compact Without Replica Repair=False;" & _
"Jet OLEDBFP=False"

in the data source you have to enter the path such as C:\...
Last edited by sahra; Sep 23rd, 2006 at 9:05 am.
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 3
Reputation: pclpossum is an unknown quantity at this point 
Solved Threads: 0
pclpossum pclpossum is offline Offline
Newbie Poster

Re: Results from Select statement differ in VB.NET and Access

 
0
  #3
Oct 1st, 2006
Thank you, but the results haven't changed. I've tried putting the db in different places, but that brings no joy either.

Do I need to have something set to allow the connection to handle complex queries such as the "like" query, or a query drawing results from multiple tables (which I'm also having trouble with)?
Peta Watson
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 90
Reputation: Inanna is on a distinguished road 
Solved Threads: 6
Inanna's Avatar
Inanna Inanna is offline Offline
Junior Poster in Training

Re: Results from Select statement differ in VB.NET and Access

 
0
  #4
Oct 1st, 2006
Uh, you didn't open the connection.
Dim adapter As OleDbDataAdapter
Dim Connection As OleDbConnection

searchResults = New DataSet

Connection = New OleDbConnection(connectionString)

Connection.Open();

adapter = New OleDbDataAdapter(searchText, Connection)
adapter.Fill(searchResults)

Connection.Close()
That should have thrown an exception. Are you catching and ignoring exceptions in a try block somewhere higher up?
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 3
Reputation: pclpossum is an unknown quantity at this point 
Solved Threads: 0
pclpossum pclpossum is offline Offline
Newbie Poster

Re: Results from Select statement differ in VB.NET and Access

 
0
  #5
Oct 1st, 2006
I don't catch an execption for that code as the connection doesn't have to be explicitly opened in this situation.

Having the
connection.Open()
in there doesn't change the results; regardless if it goes before or after the

adapter = New OleDb.OleDbDataAdapter(query, Connection)
Peta Watson
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 1
Reputation: steilx is an unknown quantity at this point 
Solved Threads: 0
steilx steilx is offline Offline
Newbie Poster

Re: Results from Select statement differ in VB.NET and Access

 
0
  #6
Mar 2nd, 2008
Try using % instead of * in the like query in the vb code .
eg:
"Select * FROM TRAINING WHERE ((Trainer Like '%Rob%'));"
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC