Unable to run a search more than once

micki_free

New member
Joined
Aug 4, 2008
Messages
1
Programming Experience
Beginner
Hi Guys

I have created a program that allows users to run searches on a Microsoft Access Database by pressing a button. The output from the search is dependant on a variable that users enter into a textbox

The problem is that users can only run a search once. If they try and run another search then the output doesn't change regardless of what is entered in textbox.

Through my investigations I have come to the conclusion that the problem is with this block of code here.
VB.NET:
Expand Collapse Copy
        OleDbCommand1.CommandText = "SELECT * FROM AccessLog WHERE Person_ID = @Person_ID"
        OleDbCommand1.Parameters.AddWithValue("@Person_ID", txtUserID.Text)


        Dim reader As OleDbDataReader = OleDbCommand1.ExecuteReader()

I'm guessing that the problem lies with the ExecuteReader method. It looks as if it only executes once (the first time you press the button). Either that or the select statement is not updated each time you press the button

Any ideas on why I can only run the search once and what I can do to correct this?
 
Try:

VB.NET:
Expand Collapse Copy
Dim reader As OleDbDataReader = OleDbCommand1.ExecuteReader(CommandBehavior.CloseConnection)
 
Back
Top