In a web project, I am trying to execute the following query:
SELECT ItemName as Name, ItemPicture as Picture, ItemHeroModif as Assistance, ItemTroopModif as Charisma, HerbCost as Herbs, GemCost as Gems FROM Item WHERE ItemId = @value0
Using breakpoints, I see I attached a value of 2 to @value0 .
Despite this, I get the following error:
Missing value for one or more required parameters.
I realized that this error usually occurs due to incorrect SQL syntax. Is there something wrong with what I did?
EDIT :
Attachment Code:
var madeForCommand = "SELECT ItemName as Name,ItemPicture as [Picture],ItemHeroModif as Assistance,ItemTroopModif as Charisma, HerbCost as Herbs, GemCost as Gems FROM Item WHERE "; OleDbCommand command = new OleDbCommand(); for (int ii = 0; ii < items.Count; ii++)// items is a list of items with IDs I want to get from the query. { madeForCommand += "ItemId =@value "+ii+" OR "; } madeForCommand = madeForCommand.Substring(0, madeForCommand.Length - 4); // making sure I trim the final or; In the case I shown, it just one item, so there are none at all.
And later:
OleDbCommand forOperations = new OleDbCommand(madeForCommand, _dbConnection);
I'm pretty sure that items[ii].ID is fine, breakpoints show that it is 2, and the attachment is going well.
EDIT 2 : I edited the code as advised by Krish and Hans, and I get the following request without any attachments:
SELECT ItemName as [Name],ItemPicture as Picture,ItemHeroModif as Assistance,ItemTroopModif as Charisma, HerbCost as Herbs, GemCost as Gems FROM [Item] WHERE (ItemID in (2));
I still get the same error if it changes something.
EDIT 3 : Running a query in Access asks me to give a value to the "ItemPicture" ... Odd; ItemPicture is a column, isn't it?