I wanted to select the data from the list of string that already being defined, and later on will filter based on that list with some conditions.
But while I am trying the below code:
List<string> inventoryList = new List<string>();
inventoryList.Add("a147");
inventoryList.Add("w150");
string.Format("SELECT * FROM (VALUES '{0}') AS InventoryList(InventoryCode)"
+ " SELECT a.[InventoryCode] FROM [InventoryList] a INNER JOIN [PlayerAccount] b WITH (NOLOCK) ON a.[InventoryCode] = b.[PlayerInventoryCode] WHERE b.[PlayerID] = 146", inventoryList);
--- Other codes to connect to the database and so on ----
It will generate it like this:
SELECT * FROM (VALUES 'System.Collections.Generic.List`1[System.String]') AS InventoryList(InventoryCode) SELECT a.[InventoryCode] FROM [InventoryList] a INNER JOIN [PlayerAccount] b WITH (NOLOCK) ON a.[InventoryCode] = b.[PlayerInventoryCode] WHERE b.[PlayerID] = 146
and the error that I am getting is:
Exception: Incorrect syntax near 'System.Collections.Generic.List`1[System.String]'.
EDIT:
Expected result will create the InventoryList table with InventoryCode for the column name with the above values inside:
InventoryList <-- table
InventoryCode <-- column name
1. a147
2. w150
Then, will be query like normal:
SELECT a.[InventoryCode] FROM InventoryList a INNER JOIN [PlayerAccount] ....
SELECT * FROM (VALUES 'a147', 'w150') AS InventoryList(InventoryCode)then, after the tableInventoryListwith the column nameInventoryCodehave the following data:a147andw150, then I will query the result with another table. ThanksinventoryListshould beString.Join("','",inventoryList.ToArray())