When using an OleDb
provider (with MS-Access in particular, but I can't exclude the same for other providers) the parsing engine looks if every part of the column list in the SELECT
clause is present in the table queried. If, for any reason (usually a typo in the column name), the engine cannot find the corresponding column it treats the name as a parameter and expects that a parameter is supplied in the OleDbCommand.Parameters
collection.
If no parameters is present then the above error is thrown.
Another possibility is the fact that you don't initialize the cmd
variable in the code above.
This implies that you are using a global variable for the OleDbCommand
.
A variable that may have been used for another query and its parameter collection is not empty.
Try to add this line before executing the query
cmd.Parameters.Clear();
cmd.CommandText = "SELECT Imeiprezimeautora FROM Tabela1";
However, if this is the problem, then I really suggest you to rethink this approach and avoid global variables for this kind of work.
There is no measurable performace penalty in defining and initializing an OleDbCommand locally