Access SQL query missing more required parameters

Name, Item, and Picture are problem words in Access queries. Enclose them in square brackets:

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);

Since bracketing those names still gave you a missing parameter complaint, I asked you to test that query in Access' query designer. In that context, Access presents a parameter input box which also includes the word which Access interprets as a parameter.

You reported Access thinks ItemPicture is a parameter. So by inspecting that table in Access Design View, you discovered the actual field name is ItemImageURL.

SELECT ItemName as [Name], ItemImageURL as [Picture], ItemHeroModif as Assistance, ItemTroopModif as Charisma, HerbCost as Herbs, GemCost as Gems
FROM [Item] WHERE ItemID in (2);

You are not taking the Where condition from outside your application so string concatenation is safe. (at least i think so)

just add the parameters like this:

var madeForCommand = "SELECT ItemName as Name,ItemPicture as Picture,ItemHeroModif as Assistance,ItemTroopModif as Charisma, HerbCost as Herbs, GemCost as Gems " +
    "FROM Item WHERE (ItemID in (";
     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.
     {
          if (i<=1) {
              madeForCommand += items[ii].ID
          }else {
              madeForCommand += "," + items[ii].ID;
          }
     }
    madeForCommand += "))"

at the end you will have a SQL query something like:

"SELECT ItemName as Name,ItemPicture as Picture,ItemHeroModif as Assistance,ItemTroopModif as Charisma, HerbCost as Herbs, GemCost as Gems " +
"FROM Item WHERE (ItemID in (1,2,3))";

Tags:

C#

Sql

Ms Access