我正在创建一个网站,但每当我运行此代码时,都会引发异常:
#Exception Details: System.IndexOutOfRangeException: There is no row at position 0.
我该如何解决这个问题?
public partial class Employee_frmSearchClaims : System.Web.UI.Page
{
int empno;
protected void Page_Load(object sender, EventArgs e)
{
if (Session["empno"] != null)
empno = int.Parse(Session["empno"].ToString());
if (!IsPostBack)
{
DataRow r = AddPoliciesOnEmployees.GetPolicyOnEmployee(empno).Tables[0].Rows[0];
Label7.Text = r["policyname"].ToString();
Label8.Text = r["policyid"].ToString();
Label9.Text = r["policyamount"].ToString();
Label10.Text = r["TotalAmount"].ToString();
Label11.Text = r["pstartdate"].ToString();
}
}
protected void btnapplicy_Click(object sender, EventArgs e)
{
if (ddlReason.SelectedItem.ToString() != "--Select--")
{
if (ddlReason.SelectedItem.Text == "Death")
{
Session["Reason"] = ddlReason.SelectedItem.Text;
Response.Redirect("frmDeathCliam.aspx");
}
else if (ddlReason.SelectedItem.Text == "Accident")
{
Session["Reason"] = ddlReason.SelectedItem.Text;
Response.Redirect("frmAccidentClaim.aspx");
}
else
{
Session["Reason"] = ddlReason.SelectedItem.Text;
Response.Redirect("frmCompleteClaim.aspx");
}
}
else
lblmsg.Text = "You have to select the reason";
}
}