Too Few Parameters Error calling query stored in Access Database

  • Thread starter Kenneth Baltrinic
  • Start date
K

Kenneth Baltrinic

I am calling a query stored in Access that requires a parameter. But the
parameter that I am passing in as part of the command does not seem to be
being recognized.

I have two queries in an Access database. They are:

SELECT [tblEventParticipants].[EventID], [tblEventParticipants].[MemberID],
[tblEventParticipants].[InterestLevelID]
FROM tblEventParticipants
WHERE ((([tblEventParticipants].[MemberID])=[CurrentMemberID]));

And

SELECT qryEventListData.*, qryCurrentMemberParticipation.MemberID,
IIf([DisplayText] Is Null,"Not Interested",[DisplayText]) AS MemberInterest,
IIf([qryCurrentMemberParticipation]![InterestLevelID] Is
Null,0,[qryCurrentMemberParticipation]![InterestLevelID]) AS
MemberInterestLevel
FROM tblInterestLevels RIGHT JOIN (qryEventListData LEFT JOIN
qryCurrentMemberParticipation ON qryEventListData.EventID =
qryCurrentMemberParticipation.EventID) ON tblInterestLevels.InterestLevelID
= qryCurrentMemberParticipation.InterestLevelID;

The important part of the above is:
1) I am calling the second query using an OdbcCommand.GetReader() call.
2) The second query includes uses the first.
3) The first query contains a parameter (CurrentMemberID)

The problem is that I call the query using the following code and get the
following error:

string sQuery =
"SELECT * FROM qryEventListDataWithParticipation";

OdbcCommand cmdGetEvents = new OdbcCommand(sQuery,
EventDataWrapper.Connection);

OdbcParameter oMemberID =
cmdGetEvents.Parameters.Add("CurrentMemberID", OdbcType.Int, 4);
oMemberID.Value = miCurrentMemberID;

OdbcDataReader dr = cmdGetEvents.ExecuteReader();

ERROR [07002] [Microsoft][ODBC Microsoft Access Driver] Too few parameters.
Expected 1.

Can anyone explain why the parameter that I am creating is not being
recognized? For what it is worth, I have attempted calling the first query
directly just to test, but that resulted in the same error.
 
V

Val Mazur

Hi Kenneth,

When you call stored query, then you should call it as a stored procedure,
not using SELECT statement. Your query should be like this and you also need
to set CommandType of your command to specify that this is a stored
procedure

string sQuery ="qryEventListDataWithParticipation";
 

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

Top