EntityDataReader
List<SelectListItem> products
Attempt to read from column ordinal '0' is not valid. With CommandBehavior.SequentialAccess, you may only read from column ordinal '1' or greater.'
<pre>public JsonResult AjaxProducts() { List<SelectListItem> products = new List<SelectListItem>(); string query = "SELECT p.prod_name_pharma_form FROM Entities.FDF_FAMILY_PROD_NAME as p"; using (EntityConnection con = new EntityConnection("name=Entities")) { using (EntityCommand cmd = new EntityCommand(query)) { cmd.CommandType = CommandType.Text; cmd.Connection = con; con.Open(); using (EntityDataReader sdr = cmd.ExecuteReader(System.Data.CommandBehavior.SequentialAccess)) { while (sdr.Read()) { products.Add(new SelectListItem { Value = sdr["prod_name_pharma_form"].ToString(), Text = sdr["prod_name_pharma_form"].ToString() }); } } } } return Json(products); }
while (sdr.Read()) { string name = sdr["prod_name_pharma_form"].ToString(); products.Add(new SelectListItem { Value = name, Text = name }); }
try/catch
sdr.HasRows
sdr
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)