cenbnk_nigeria2
New Member
after running these codes no rows showen I debugged and found that \[code\]foreach\[/code\] did not get into block.where is the wrong? database Diagram:
Default.aspx.cs:\[code\]using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.HtmlControls;using System.Web.UI.WebControls;namespace ETest{public partial class Default : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { using (personDbEntities context = new personDbEntities()) { foreach (Contact cn in context.Contacts) { ProcessContact(cn); } } } private void ProcessContact(Contact contactParam) { HtmlTableRow row = new HtmlTableRow(); row.Cells.Add(CreateTableCell(contactParam.id.ToString())); row.Cells.Add(CreateTableCell(contactParam.fname.ToString())); row.Cells.Add(CreateTableCell(contactParam.lname.ToString())); row.Cells.Add(CreateTableCell(contactParam.phone.ToString())); resultsTable.Rows.Add(row); } private HtmlTableCell CreateTableCell(string textParam) { return new HtmlTableCell() { InnerText = textParam }; }}\[/code\]}Default.aspx:\[code\]<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="ETest.Default" %><!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"></head><body><div id="info" runat="server"/><table id="resultsTable" runat="server" rules="cols"><tr><th>id </th><th>fname </th><th>lname </th><th>phone </th></tr></table></body></html>\[/code\]Connection String:\[code\]<connectionStrings><add name="personDbEntities" connectionString="metadata=res://*/EM.csdl|res://*/EM.ssdl|res://*/EM.msl;provider=System.Data.SqlClient;provider connection string="data source=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\personDb.mdf;integrated security=True;connect timeout=30;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" /></connectionStrings>\[/code\]