Link to home
Create AccountLog in
Avatar of pillmill
pillmill

asked on

Parameter 'ID' not found in the collection.

I get this error when I execute the command:

cmd.Parameters["ID"].Value = row["USER"];

where cmd is a MySqCommand and row is an element of a
XMLDoc.DataSet.Table

I thought "collection" referred to the table.

But I find the element in BOTH the cmd and in
the Table. How can I debug this?
ASKER CERTIFIED SOLUTION
Avatar of Daniel Wilson
Daniel Wilson
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of pillmill
pillmill

ASKER

Thanks. I found the problem:

The first parameter was ID and second email, added as:
cmd.Parameters.Add(new MySqlParameter("ID", MySqlDbType.Int32))
cmd.Parameters.Add(new MySqlParameter("email", MySqlDbType.String))

The assignment of the values of the parameters was done incorrectly as:
cmd.Parameters[0].Value = email;

When I changed the order, the error seemed to be corrected.
The error message didn't seem very informative though.

 
First of all do you try to run SQL query or storage procedure?
for storage procedure set:
cmd.CommandType = CommandType.StoredProcedure;

Then you can try to add parameter:
cmd.Parameters.Add("@ID", row["USER"]);
or
cmd.Parameters.Add("?ID", row["USER"]);