Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > .NET 3.5 and Visual Studio. 2008 > Visual Studio 2008
Visual Studio 2008 For discussing Visual Studio 2008. Please post code questions about a specific language (C#, VB, ASP.NET, etc) in the correct language forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Studio 2008 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old October 27th, 2008, 06:26 PM
Registered User
Join Date: Oct 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Search button doesn't search Access DB


I have a Microsoft Access DB connected to a Windows Form Application.
This DB is going to be used as a tracking system. I tried to code the search button to check the Access file based on a certain criteria that is typed in by the user. There are several fields:
Last Name, First Name, etc. Below is the code I have to try to have search the Access DB file. Am I missing another piece that should return the data searched? I tried checking http://msdn.microsoft.com and I have a book for windows form applications but couldn't find an answer. Any help in the right direction would be appreciated.

  Public Sub ReadMyData(ByVal myConnString As String)
  Dim mySelectQuery As String = "SELECT Medical Record Number, Last Name, First Name FROM Table1 where lastname ='" + TextBox1.Text + "'"
        Dim myConnection As New OleDbConnection(myConnString)
        Dim myCommand As New OleDbCommand(mySelectQuery, myConnection)
        Dim myReader As OleDbDataReader
        myReader = myCommand.ExecuteReader()
        While myReader.Read()
            Console.WriteLine(myReader.GetInt32(0).ToString() + ", " _
            + myReader.GetString(1))
        End While

Thank you.
Old October 27th, 2008, 07:36 PM
Friend of Wrox
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts

Did you DEBUG???

Just for starters, did you put a breakpoint on the line where you create the query and make sure that the SQL was valid?

If it looks valid, did you then take that string and try it WITHIN ACCESS? See if that query actually returns anything?

p.s.: Just FYI, that query is *NOT* legal SQL. Which I guess means I know you didn't debug.

p.p.s.: Here's a hint for you: You are doing a SELECT for "Last Name" and yet your WHERE clause is trying to match up on the field "lastname". *SURELY* that table doesn't have BOTH a field named "Last Name" *and* one named "lastname". Surely.

Similar Threads
Thread Thread Starter Forum Replies Last Post
search button ct Excel VBA 0 April 11th, 2006 09:50 AM
Q about search DB... ugmos Classic ASP Databases 1 February 27th, 2006 07:49 PM
Create Search Button on Access Form BKILBAN Access VBA 1 February 27th, 2004 09:01 AM
Error When Trying to Search in Access DB Using ASP mvollmer Classic ASP Databases 3 October 10th, 2003 10:52 AM
Problem using wildcards to search an Access DB taliesin Classic ASP Databases 4 June 23rd, 2003 11:13 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.