Server Error in '/' Application.

There is no row at position 0.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IndexOutOfRangeException: There is no row at position 0.

Source Error:


Line 1:  using System;using System.Data;using System.Data.SqlClient;using System.Configuration;public partial class DynamicPage:System.Web.UI.Page{protected void Page_Load(object sender,EventArgs e){if(!this.IsPostBack){this.PopulatePage();}} private void PopulatePage(){string PageName=this.Page.RouteData.Values["PageName"].ToString();string conString=ConfigurationManager.ConnectionStrings["constr"].ConnectionString; using (SqlConnection con=new SqlConnection(conString)){using(SqlCommand cmd=new SqlCommand("pDynamicPage")){cmd.CommandType=CommandType.StoredProcedure;using (SqlDataAdapter sda=new SqlDataAdapter()){cmd.Parameters.AddWithValue("@Page",PageName); cmd.Connection=con;sda.SelectCommand=cmd;using(DataTable dt=new DataTable()){sda.Fill(dt); this.Title=dt.Rows[0]["Title"].ToString();this.MetaKeywords=dt.Rows[0]["Keywords"].ToString(); this.MetaDescription=dt.Rows[0]["Description"].ToString();lblTitle.Text=dt.Rows[0]["h1"].ToString(); lblContent.Text=dt.Rows[0]["Content"].ToString(); lblPublishedDate.Text =(DateTime.Now).ToString();}}}}}}

Source File: c:\inetpub\vhosts\neghinbar.com\law-offices.ir\DynamicPage.aspx.cs    Line: 1

Stack Trace:


[IndexOutOfRangeException: There is no row at position 0.]
   System.Data.RBTree`1.GetNodeByIndex(Int32 userIndex) +2441293
   System.Data.DataRowCollection.get_Item(Int32 index) +19
   DynamicPage.PopulatePage() in c:\inetpub\vhosts\neghinbar.com\law-offices.ir\DynamicPage.aspx.cs:1
   DynamicPage.Page_Load(Object sender, EventArgs e) in c:\inetpub\vhosts\neghinbar.com\law-offices.ir\DynamicPage.aspx.cs:1
   System.Web.UI.Control.OnLoad(EventArgs e) +106
   System.Web.UI.Control.LoadRecursive() +68
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3785


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.3930.0