Abdullah Zafar

Abdullah Zafar

  • NA
  • 4
  • 3.2k

C#, Restful Web Api on MVC4

Feb 14 2014 1:13 PM
i am new in c#, and making a  Restful API on  MVC4,
 i am using following code and gets an error on
 " foreach (DataRow menuDR in menuDataSet.Tables [7].Rows)"
 
IndexOutOfRangeException was unhandled by user code, and in details in show "cannot find table7"
i used the same approach with 1 table database and it was working, i don't know how to handle this exception and tried various things to get it sort.... 
 
public IEnumerable<RestaurantsMenu> GetAllMenu()
{
menuCon = new SqlConnection ("Data Source=MyPc\\MyPc;Initial Catalog=MENU;Integrated Security=True");
menuDataAdapter = new SqlDataAdapter (" SELECT * FROM RestaurantsMenu ", menuCon);
foreach (DataRow menuDR in menuDataSet.Tables [7].Rows)
{
Rst_Menu.Add(new RestaurantsMenu(){Restaurant_ID = int .Parse (menuDR[0].ToString()), RestaurantName =menuDR[1].ToString(),
Menu =menuDR[2].ToString(), Price=int .Parse (menuDR[3].ToString()) } );
}
return Rst_Menu;
}
 

Answers (1)