Click here to Skip to main content
15,920,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working with a windows form in C#. I am using a datareader to populate a listbox. However, I get a message when I ExecuteReader "No value given for one or more required parameters". But I can't find anything wrong. Can you point me in the right direction? Here is the relevant code.

private void loaddata()
            OleDbConnection cn = new OleDbConnection();
            cn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Access Stuff\ASME_Plate.accdb;Persist Security Info = False;";
            string q = "SELECT DISTINCT [Spec_No] FROM ASME_Plate";
            OleDbCommand cmd = new OleDbCommand(q, cn);
  Error on this line              OleDbDataReader dr = cmd.ExecuteReader();
                if (dr.HasRows)
                    while (dr.Read())

What I have tried:

I tried much code change without success.
Updated 13-May-22 22:21pm
RedDk 8-May-22 17:47pm    
I suggest you use VS Object Browser to identify valid/referenced procedures and methods and functions then select a corresponding structure in your code (because it wouldn't make much sense to look for something that doesn't exist as such in the documentation) and give it the old F1 to bring up the HELP.

The documents are riddled with sample/example ... and there's no way to get it wrong copying the same style or at least starting with what is right AND WORKS.
BobbyStrain 8-May-22 21:43pm    
I followed your advice. The same notice appears. The ExecuteReader() seem to still be looking for a parameter. It seem there are three overloads, and I tried one to no avail. I'll keep looking It seems like a simple operation to be so troublesome.
Richard MacCutchan 9-May-22 4:09am    
Please show the actual message and which line it occurs on.
BobbyStrain 9-May-22 12:13pm    
OK. I updated to show the message and where the error occurs. Closing the message, the code continues to execute properly, except for the rest of this method.
Richard MacCutchan 9-May-22 12:36pm    
I have tried the same sequence of instructions and cannot get it to fail. There is something wrong with your application that we cannot see.

1 solution

The problem arose due to a mis-spelled table name. The exception message from OLEDB did not help.
Share this answer
Maciej Los 14-May-22 14:19pm    

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900