| | |
Results from Select statement differ in VB.NET and Access
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2006
Posts: 3
Reputation:
Solved Threads: 0
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:
(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
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:
VB.NET Syntax (Toggle Plain Text)
Dim adapter As OleDb.OleDbDataAdapter Dim Connection As OleDb.OleDbConnection searchResults = New DataSet Connection = New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Trainers.mdb") adapter = New OleDb.OleDbDataAdapter(searchText, Connection) adapter.Fill(searchResults) Connection.Close() ' Where searchText = ' "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
•
•
Join Date: Sep 2006
Posts: 1
Reputation:
Solved Threads: 0
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 OLEDB
ystem 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 OLEDB
FP=False"
in the data source you have to enter the path such as C:\...
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 OLEDB
ystem 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 OLEDB
FP=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.
•
•
Join Date: Sep 2006
Posts: 3
Reputation:
Solved Threads: 0
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)?
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
Uh, you didn't open the connection.
That should have thrown an exception. Are you catching and ignoring exceptions in a try block somewhere higher up?
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()![]() |
Similar Threads
- Question about SELECT statement (MySQL)
- Getting current value in Select Statement (MS SQL)
- cfselect issue trying to get results from a sql select statement (ColdFusion)
- Program Problem with a select statement to access Data base (C)
Other Threads in the VB.NET Forum
- Previous Thread: Field token out of range
- Next Thread: For the love of GOD! Someone please help me!!!
| Thread Tools | Search this Thread |
.net .net2008 2005 2008 access account arithmetic array arrays basic bing button buttons c# center check checkbox code combobox convert crystalreport data database datagrid datagridview date dissertation dissertations dropdownlist excel fade file-dialog filter ftp generatetags google gridview hardcopy images inline input insert intel internet listview mobile monitor ms net networking objects output panel passingparameters picturebox picturebox1 port position print printing problem project read remove save searchbox searchvb.net select serial server shutdown soap sorting survey table tcp temperature text textbox timer timespan toolbox trim update user validation vb vb.net vb.netformclosing()eventpictureboxmessagebox vb2008 vbnet view visual visualbasic visualbasic.net visualstudio2008 web winforms wpf year





