Missing required parameter error

D

Damon

I've distilled this down into the simplest possible code fragment and
this still doesn't make any sense. I'm trying to run a select query on
an access database, and the query has NO parameters. And yet, I'm
still getting a "No value given for one or more required parameters"
error. What gives?

Here's my code. I put it in a Form_Load subroutine of a blank .aspx
page so that nothing else external would affect it. (And yes, the
Access database is meant to have a user name and password.)

Protected Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Dim myConnection As System.Data.OleDb.OleDbConnection
Dim connStr As String
connStr = String.Format("Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=" & Server.MapPath(MyGlobals.ACCESS_DB) & "; " & _
"Persist Security Info=True; Jet
OLEDB:Engine Type=5; Jet OLEDB:System Database=" & _
MyGlobals.ACCESS_SYSTEM_MDW & "; User
ID=" & _
"XXXXX" & "; Password=" & _
"XXXXX")
myConnection = New System.Data.OleDb.OleDbConnection(connStr)
Dim mySelectQuery As String
Dim myCommand As New System.Data.OleDb.OleDbCommand()

mySelectQuery = "SELECT EmployeeID, LastName, FirstName,
EmpFileNumber " & _
"FROM employees"
myCommand = New System.Data.OleDb.OleDbCommand(mySelectQuery,
myConnection)

myConnection.Open()

Dim myReader As System.Data.OleDb.OleDbDataReader
myReader =
myCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
<-- error happens here

myConnection = Nothing
End Sub

Any ideas, anyone?

Damon
 
T

Trevor Benedict R

add
myCommand.CommandType = CommandType.Text
before the execute.

Regards,

Trevor Benedict R
MCSD
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top