Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to access items of an IQueryable<T> by index
    text
    copied!<p>I'm new to c#. I'm attempting to use what ought be a list(?) produced by a linq query to build a table on an ordering form. Part of that involves referencing a specific item in that list as below:</p> <pre><code>using (CellOrderingDBEntities db = new CellOrderingDBEntities()) { var AccessoryItems = from AccessoryDescription in db.Accessories join HardwareID in db.HardwareTypes on AccessoryDescription.HardwareType equals HardwareID.HardwareID where AccessoryDescription.DateRetired == null select AccessoryDescription; List&lt;Device&gt; DevicesList = (List&lt;Device&gt;)Session["DevicesList"]; Guid AccessoriesOrder = (from ServiceID in db.TypeOfServices where ServiceID.ServiceType == "Accessories Order" select ServiceID.ServiceID).FirstOrDefault(); //This Int is used to build the accessories table int AccessoryRows = AccessoryItems.Count(); if (SType == AccessoriesOrder) { for (int r = 0; r &lt;= AccessoryRows; r++) { TableRow row = new TableRow(); for (int c = 0; c &lt; 3; c++) { TableCell cell = new TableCell(); TextBox tb = new TextBox(); int ai = 0; int ri = 0; tb.ID = "TextBoxRow_" + r + "Col_" + c; if (c == 0) { cell.Controls.Add(tb); } else if (c == 1) { cell.Text = AccessoryItems[ai]; ai++; } } } } </code></pre> <p>I'm stuck with this error though:</p> <pre> Cannot apply indexing with [] to an expression of type 'System.Linq.IQueryable&lt;Data.Accessory&gt;' </pre> <p>I've tried converting it to a list of strings but for reasons I do not understand why it won't let me access the <code>IQueryable</code> by index. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload