I am getting the an System.IndexOutOfRangeException exception on "count". Any idea what I am doing wrong?
[HttpGet]
public IHttpActionResult shopnameandnoofcomp()
{
SqlDataReader dataReader = null;
SqlConnection myConnection = new SqlConnection();
myConnection.ConnectionString = dbpath;
myConnection.Open();
SqlCommand sqlCmd = new SqlCommand();
sqlCmd.CommandType = CommandType.Text;
sqlCmd.CommandText = "selectshopname,count(shopname) from Complain group by shopname";
sqlCmd.Connection = myConnection;
List<Complain> cmp = new List<Complain>();
dataReader = sqlCmd.ExecuteReader();
while (dataReader.Read())
{
cmp.Add(new Complain
{
shopname= dataReader["shopname"].ToString(),
Count = dataReader["count"].ToString(),
});
}
myConnection.Close();
return Ok(cmp);
}