flusescally
New Member
I've data (3 variables) to fetch from ms access database (Product table) and to display it on aspx page. I've managed to display only first row of data. Seems that problem is in aspx page code in foreach loop. I just can't get my head round.... Please help. Thanks in advance!Here is ProductController class: \[code\] public ActionResult Index() { string str = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\\vindom\\Desktop\\DB2.accdb"; // connection string from database Properties OleDbConnection con = new OleDbConnection(str); OleDbCommand cmd; OleDbDataReader reader; con.Open(); { cmd = new OleDbCommand("SELECT * FROM product", con); reader = cmd.ExecuteReader(); while(reader.Read()) { ViewData["Prod_Type"] = reader.GetValue(0); ViewData["Prod_N"] = reader.GetValue(1); ViewData["Prod_d"] = reader.GetValue(2); } con.Close(); return View(); } }\[/code\]And here is the aspx code:\[code\] <table> <tr> <th>Product Type</th> <th>Product Number</th> <th>Product Details</th> <th></th> </tr> <%@foreach (var item in View) {%> <tr> <td><%= Html.Encode(ViewData["Prod_Type"]) %></td> <td><%= Html.Encode(ViewData["Prod_N"]) %></td> <td><%= Html.Encode(ViewData["Prod_d"]) %></td> </tr> <%}%> </table>\[/code\]