如何删除异常:Message ="位置0处没有行。 [英] how to remove exception : Message = "There is no row at position 0."
本文介绍了如何删除异常:Message ="位置0处没有行。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好我的申请是针对离开模块。什么时候会计算几天和几天试图提交请假它无法保存记录。它会给出异常:
Hi My application is for Leave module. When it will count days & trying to submit the leave it is not able to save record. It will give exception:
Message = "There is no row at position 0."
我的IsValidLeave函数部分是:
And my IsValidLeave function part is:
public bool IsValidLeave(string leaveTypeID)
{
try
{
if (drdwnLeaveType.SelectedIndex == 0)
{
ScriptManager.RegisterStartupScript(Page, GetType(), "key1", "alert('Please select Leave Type');", true);
DateOfJoin();
ApplyLeave();
return false;
}
if (countdays())
{
double NOD = Convert.ToDouble(ViewState["NoOfDays"].ToString());
if (chkHalfLeave.Checked)
{
NOD = NOD * 2;
}
bool go = false;
if (leaveTypeID == "2" && NOD > 3)
{
if (ViewState["Medical"].ToString() == "")
{
ScriptManager.RegisterStartupScript(this, GetType(), "AlertCode", "alert('Medical Certificate is required to avail Sick Leave more than 3 Days')", true);
return false;
}
else
{
go = true;
}
}
else
{
go = true;
}
if (go == true)
{
dt.OpenCon();
string qry = "select MA_LeaveTypeName from master_LeaveType where MA_LeaveType= '" + leaveTypeID + "'";
string LeaveType = dt.ExecuteScalar(qry);
string[] LeaveTypeName = LeaveType.Split(' ');
dt.Dispose();
if (ShowYear.Visible == true) /*Check Leave Balance From Current Year*/
{
string CrYr = DateTime.Now.Year.ToString();
ArrayList arrchkleave = LeaveManagement.GetAppliedLeaveBalance(leaveTypeID, Session["U_Emp_Code"].ToString(), CrYr);
leavebal = Convert.ToDouble(arrchkleave[0]);
}
else if (ShowYear.Visible == false) /*Check Leave Balance From Previous Year*/
{
int CrYr = DateTime.Now.Year;
string PVYr = Convert.ToString(CrYr - 1);
ArrayList arrchkleave = LeaveManagement.GetAppliedLeaveBalance(leaveTypeID, Session["U_Emp_Code"].ToString(), PVYr);
leavebal = Convert.ToDouble(arrchkleave[0]);
}
if (leavebal > 0)
{
double bal = leavebal - Convert.ToDouble(ViewState["NoOfDays"].ToString());
if (bal < 0 || bal == 0)//(bal > 0 || bal == 0//Original old) again replace from new to old(bal < 0 || bal >= 0)//changes made by Seema bal < 0 instead of bal > 0
{
return true;
}
else
{
//ScriptManager.RegisterStartupScript(this, GetType(), "AlertCode", "alert('You have only " + leavebal + " " + LeaveTypeName[0] + " Leaves remaining.')", true);
ScriptManager.RegisterStartupScript(this, GetType(), "AlertCode", "alert('You have Cross The Limits')", true);
return false;
}
}
else if (leavebal == 0 || leavebal < 0)
{
return true;
}
else
{
ScriptManager.RegisterStartupScript(this, GetType(), "AlertCode", "alert('You have availed all " + LeaveTypeName[0] + " Leaves.')", true);
return false;
}
}
else
{
return false;
}
}
else
{
DateOfJoin();
ApplyLeave();
return false;
}
}
catch (Exception ex)
{
return false;
}
}
所以如何删除此错误。
so how can i remove this error.
推荐答案
请检查函数GetAppliedLeaveBalance()是否按照注释中的建议为LWP返回任何数据。
另外一个更好的做法是检查arrchkleave
不是null并且在使用任何值之前有一些元素它。
以下代码确保arrchkleave至少有一个元素并避免您遇到的异常。
Hi,
Please check whether the function GetAppliedLeaveBalance() returns any data back for LWP as suggested in the comments.
Also it is a better practice to checkarrchkleave
is not null and has some elements before using any value from it.
The below code makes sure arrchkleave has at-least one element and avoids the exception you are facing.
if(arrchkleave != null && arrchkleave.Count > 0)
{
leavebal = Convert.ToDouble(arrchkleave[0]);
}
这篇关于如何删除异常:Message ="位置0处没有行。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文