Hi Team,
I am a fresher in the software development...and facing a issue with my firm inhouse allpication which is designed for all in one purpose ...
Daily my manager getting this error from the portal
Cannot find table 0.
at System.Data.DataTableCollection.get_Item(Int32 index) at ExpenseFormList.GetData() in d:\unistanz.co.in\ExpenseFormList.aspx.cs:line 242
i am writing the entire page code here and please help me in this issue..
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
public partial class ExpenseFormList : System.Web.UI.Page
{
CommonLayerClasses.BLL mobjBll = new CommonLayerClasses.BLL();
Unistanz.SendError.Details.SendErrorDetails unistanzSendEmail;
SqlParameter[] gmarrParam;
string strFromEmailAddress;
string strToEmailAddress;
string strCCEmailAddress;
string strSubjectofSupportMail;
string strErrorOn;
string strConnString;
string strErrorOnCatch;
string strSMTPServer;
string strSystemName;
string strErrorOnServer;
protected void Page_Load(object sender, EventArgs e)
{
if (Session["UserName"] == "")
{
Response.Write("your session has expire.please login again");
Response.End();
}
try
{
unistanzSendEmail = new Unistanz.SendError.Details.SendErrorDetails();
strSMTPServer = ConfigurationManager.AppSettings["SMTPHost"];
strSystemName = ConfigurationManager.AppSettings["SupportAppName"];
strFromEmailAddress = ConfigurationManager.AppSettings["SupportFromEmailID"];
strToEmailAddress = ConfigurationManager.AppSettings["SupportToEmailID"];
strCCEmailAddress = ConfigurationManager.AppSettings["SupportCCEmailID"];
strErrorOnServer = ConfigurationManager.AppSettings["ErrorOnServer"];
strSubjectofSupportMail = strErrorOnServer + " " + strSystemName;
strErrorOn = Page.AppRelativeVirtualPath + ":" + Page.ClientQueryString;
strConnString = ConfigurationManager.AppSettings["sqlConn"];
strErrorOnCatch = ConfigurationManager.AppSettings["ErrorOnCatch"];
if (Page.IsPostBack == false)
{
Label lbl = default(Label);
lbl = (Label)Master.FindControl("lblPageTitle");
lbl.Text = "Expense Tracker >> List";
lblMsg.Text = hdnMsg.Value;
getSubmittedby();
if (Request.QueryString["PageIndex"] != string.Empty)
{
gvExpenseList.PageIndex = Convert.ToInt32(Request.QueryString["PageIndex"]);
txtFrom_Time.Text = Convert.ToString(Request.QueryString["FromTime"]);
txtTo_Time.Text = Convert.ToString(Request.QueryString["ToTime"]);
ddlSrchBy.SelectedValue = Convert.ToString(Request.QueryString["DdlSrchBy"]);
txtSrch.Text = Convert.ToString(Request.QueryString["TxtSearch"]);
txtenterSrch.Text = Convert.ToString(Request.QueryString["TxtenterSrch"]);
txtSrchdate.Text = Convert.ToString(Request.QueryString["TxtSearchDate"]);
txtSrchReleasedate.Text = Convert.ToString(Request.QueryString["TxtSearchReleaseDate"]);
ddlSubmittedBy.SelectedValue = Convert.ToString(Request.QueryString["DdlSubmittedBy"]);
ddlStatus.SelectedValue = Convert.ToString(Request.QueryString["DdlStatus"]);
}
GetData();
}
}
catch (Exception ex)
{
lblMsg.Visible = true;
lblMsg.Text = strErrorOnCatch;
unistanzSendEmail.SendEmailForError(strSMTPServer, strFromEmailAddress, strSubjectofSupportMail + " at Page_Load Event", ex.Message + "<br /><br /><br />" + ex.StackTrace + "<br /><br /><br />", strToEmailAddress, strCCEmailAddress, strCCEmailAddress);
}
}
public void GetData()
{
DataSet ldsExpense = new DataSet();
try
{
gmarrParam = new SqlParameter[9];
gmarrParam[0] = new SqlParameter("@FromDate", SqlDbType.VarChar, 15);
if (txtFrom_Time.Text == "")
{
gmarrParam[0].Value = DBNull.Value;
}
else
{
gmarrParam[0].Value = txtFrom_Time.Text.ToString().Trim();
}
gmarrParam[1] = new SqlParameter("@Todate", SqlDbType.VarChar, 15);
if (txtTo_Time.Text == "")
{
gmarrParam[1].Value = DBNull.Value;
}
else
{
gmarrParam[1].Value = txtTo_Time.Text.ToString().Trim();
}
gmarrParam[2] = new SqlParameter("@SrcExpenseID", SqlDbType.Int);
if (ddlSrchBy.SelectedValue == "SrcExpenseID")
{
if (txtSrch.Text == String.Empty)
{
gmarrParam[2].Value = DBNull.Value;
}
else
{
gmarrParam[2].Value = Convert.ToInt64(txtSrch.Text);
}
}
else
{
gmarrParam[2].Value = DBNull.Value;
}
gmarrParam[3] = new SqlParameter("@SrcExpenseDetails", SqlDbType.VarChar,25);
if (ddlSrchBy.SelectedValue == "SrcExpenseDetails")
{
if (txtenterSrch.Text == String.Empty)
{
gmarrParam[3].Value = DBNull.Value;
}
else
{
gmarrParam[3].Value = Convert.ToString(txtenterSrch.Text);
}
}
else
{
gmarrParam[3].Value = DBNull.Value;
}
gmarrParam[4] = new SqlParameter("@SrcExpectedExpenseDate", SqlDbType.VarChar,15);
if (ddlSrchBy.SelectedValue == "SrcExpectedExpenseDate")
{
if (txtSrchdate.Text == String.Empty)
{
gmarrParam[4].Value = DBNull.Value;
}
else
{
gmarrParam[4].Value = Convert.ToString(txtSrchdate.Text);
}
}
else
{
gmarrParam[4].Value = DBNull.Value;
}
gmarrParam[5] = new SqlParameter("@SrcExpectedReleaseDate", SqlDbType.VarChar, 15);
if (ddlSrchBy.SelectedValue == "SrcExpectedReleaseDate")
{
if (txtSrchReleasedate.Text == String.Empty)
{
gmarrParam[5].Value = DBNull.Value;
}
else
{
gmarrParam[5].Value = Convert.ToString(txtSrchReleasedate.Text);
}
}
else
{
gmarrParam[5].Value = DBNull.Value;
}
gmarrParam[6] = new SqlParameter("@SrcSubmittedBy", SqlDbType.Int);
if (ddlSrchBy.SelectedValue == "SrcSubmittedBy")
{
if (ddlSubmittedBy.SelectedValue == "All")
{ gmarrParam[6].Value = DBNull.Value; }
else
{ gmarrParam[6].Value = Convert.ToInt64(ddlSubmittedBy.SelectedValue); }
}
else if (ddlSubmittedBy.SelectedValue == "All")
{
gmarrParam[6].Value = DBNull.Value;
}
else
{
gmarrParam[6].Value = DBNull.Value;
}
gmarrParam[7] = new SqlParameter("@SrchBy", SqlDbType.VarChar, 100);
if (ddlSrchBy.SelectedValue == "All")
{
gmarrParam[7].Value = DBNull.Value;
}
else if (ddlSrchBy.SelectedValue == "SrcStatus")
{
if (ddlStatus.SelectedValue == "All")
{
gmarrParam[7].Value = DBNull.Value;
}
else
{
gmarrParam[7].Value = Convert.ToString(ddlStatus.SelectedItem.Text);
}
}
else
{
gmarrParam[7].Value = DBNull.Value;
}
gmarrParam[8] = new SqlParameter("@UserId", SqlDbType.Int);
gmarrParam[8].Value = Session["UserId"];
mobjBll.ProcedureName = "getExpenseFormList";
mobjBll.ParametersList = gmarrParam;
ldsExpense = mobjBll.GetList();
gvExpenseList.PageSize = Convert.ToInt16(ConfigurationManager.AppSettings["NoOfRecordsPerPage"]);
if (ldsExpense.Tables[0].Rows.Count > 0)
{
gvExpenseList.Visible = true;
gvExpenseList.DataSource = ldsExpense;
gvExpenseList.DataBind();
tblNoRecord.Visible = false;
tblGrid.Visible = true;
tblNav.Visible = true;
}
else
{
tblNoRecord.Visible = true;
gvExpenseList.Visible = false;
tblNav.Visible = false;
tblGrid.Visible = false;
}
if (ddlSrchBy.SelectedValue == "All")
{
txtSrch.Style["display"] = "none";
imgSrchcal.Style["display"] = "none";
imgSrchclear.Style["display"] = "none";
imgReleasecal.Style["display"] = "none";
imgReleaseclear.Style["display"] = "none";
ddlStatus.Style["display"] = "none";
txtenterSrch.Style["display"] = "none";
}
if (ddlSrchBy.SelectedValue == "SrcExpenseID")
{
txtSrch.Style["display"] = "inline";
imgSrchcal.Style["display"] = "none";
imgSrchclear.Style["display"] = "none";
imgReleasecal.Style["display"] = "none";
imgReleaseclear.Style["display"] = "none";
ddlStatus.Style["display"] = "none";
}
if (ddlSrchBy.SelectedValue == "SrcSubmittedBy")
{
ddlSubmittedBy.Style["display"] = "inline";
imgSrchcal.Style["display"] = "none";
imgSrchclear.Style["display"] = "none";
imgReleasecal.Style["display"] = "none";
imgReleaseclear.Style["display"] = "none";
ddlStatus.Style["display"] = "none";
txtenterSrch.Style["display"] = "none";
txtSrch.Style["display"] = "none";
}
else
{
ddlSubmittedBy.Style["display"] = "none";
ddlSubmittedBy.Style["display"] = "none";
imgReleasecal.Style["display"] = "none";
imgReleaseclear.Style["display"] = "none";
txtenterSrch.Style["display"] = "none";
}
if (ddlSrchBy.SelectedValue == "SrcExpenseDetails")
{
txtenterSrch.Style["display"] = "inline";
txtSrchdate.Style["display"] = "none";
imgSrchcal.Style["display"] = "none";
imgSrchclear.Style["display"] = "none";
imgReleasecal.Style["display"] = "none";
imgReleaseclear.Style["display"] = "none";
ddlStatus.Style["display"] = "none";
txtSrch.Style["Display"] = "none";
}
if (ddlSrchBy.SelectedValue == "SrcExpectedExpenseDate")
{
txtSrchdate.Style["display"] = "inline";
imgSrchcal.Style["display"] = "inline";
imgSrchclear.Style["display"] = "inline";
imgReleasecal.Style["display"] = "none";
imgReleaseclear.Style["display"] = "none";
ddlStatus.Style["display"] = "none";
}
else
{
txtSrchdate.Style["display"] = "none";
imgSrchcal.Style["display"] = "none";
imgSrchclear.Style["display"] = "none";
}
if (ddlSrchBy.SelectedValue == "SrcExpectedReleaseDate")
{
txtSrchReleasedate.Style["display"] = "inline";
imgReleasecal.Style["display"] = "inline";
imgReleaseclear.Style["display"] = "inline";
imgSrchcal.Style["display"] = "none";
imgSrchclear.Style["display"] = "none";
ddlStatus.Style["display"] = "none";
txtenterSrch.Style["display"] = "none";
}
else
{
txtSrchReleasedate.Style["display"] = "none";
imgReleasecal.Style["display"] = "none";
imgReleaseclear.Style["display"] = "none";
}
if (ddlSrchBy.SelectedValue == "SrcStatus")
{
ddlStatus.Style["display"] = "inline";
imgSrchcal.Style["display"] = "none";
imgSrchclear.Style["display"] = "none";
imgSrchcal.Style["display"] = "none";
imgSrchclear.Style["display"] = "none";
txtenterSrch.Style["display"] = "none";
}
else
{
ddlStatus.Style["display"] = "none";
}
if (gvExpenseList.PageIndex == gvExpenseList.PageCount - 1)
{
lbtnNext.Enabled = false;
lbtnLast.Enabled = false;
}
else
{
lbtnNext.Enabled = true;
lbtnLast.Enabled = true;
}
if (gvExpenseList.PageIndex == 0)
{
lbtnFirst.Enabled = false;
lbtnPrev.Enabled = false;
}
else
{
lbtnFirst.Enabled = true;
lbtnPrev.Enabled = true;
}
lblRecords.Text = Convert.ToString(ldsExpense.Tables[0].Rows.Count);
lblPage.Text = Convert.ToString(gvExpenseList.PageIndex + 1) + "/" + Convert.ToString(gvExpenseList.PageCount);
hdnPageIndex.Value = Convert.ToString(gvExpenseList.PageIndex);
}
catch (Exception ex)
{
lblMsg.Visible = true;
lblMsg.Text = strErrorOnCatch;
unistanzSendEmail.SendEmailForError(strSMTPServer, strFromEmailAddress, strSubjectofSupportMail + " at BindData Subroutin", ex.Message + "<br /><br /><br />" + ex.StackTrace + "<br /><br /><br />", strToEmailAddress, strCCEmailAddress, "");
}
finally
{
gmarrParam = null;
ldsExpense = null;
}
}
protected void lbtnFirst_Click(object sender, EventArgs e)
{
try
{
lblMsg.Text = "";
gvExpenseList.PageIndex = 0;
hdnPageIndex.Value = Convert.ToString(gvExpenseList.PageIndex);
GetData();
}
catch (Exception ex)
{
lblMsg.Visible = true;
lblMsg.Text = strErrorOnCatch;
unistanzSendEmail.SendEmailForError(strSMTPServer, strFromEmailAddress, strSubjectofSupportMail + " at BindData Subroutin", ex.Message + "<br /><br /><br />" + ex.StackTrace + "<br /><br /><br />", strToEmailAddress, strCCEmailAddress, "");
}
}
protected void lbtnPrev_Click(object sender, EventArgs e)
{
try
{
lblMsg.Text = "";
if (gvExpenseList.PageIndex > 0)
{
gvExpenseList.PageIndex = gvExpenseList.PageIndex - 1;
hdnPageIndex.Value = Convert.ToString(gvExpenseList.PageIndex);
}
GetData();
}
catch (Exception ex)
{
lblMsg.Visible = true;
lblMsg.Text = strErrorOnCatch;
unistanzSendEmail.SendEmailForError(strSMTPServer, strFromEmailAddress, strSubjectofSupportMail + " at BindData Subroutin", ex.Message + "<br /><br /><br />" + ex.StackTrace + "<br /><br /><br />", strToEmailAddress, strCCEmailAddress, "");
}
}
protected void lbtnNext_Click(object sender, EventArgs e)
{
try
{
lblMsg.Text = "";
if (gvExpenseList.PageIndex < gvExpenseList.PageCount - 1)
{
gvExpenseList.PageIndex = gvExpenseList.PageIndex + 1;
hdnPageIndex.Value = Convert.ToString(gvExpenseList.PageIndex);
}
GetData();
}
catch (Exception ex)
{
lblMsg.Visible = true;
lblMsg.Text = strErrorOnCatch;
unistanzSendEmail.SendEmailForError(strSMTPServer, strFromEmailAddress, strSubjectofSupportMail + " at BindData Subroutin", ex.Message + "<br /><br /><br />" + ex.StackTrace + "<br /><br /><br />", strToEmailAddress, strCCEmailAddress, "");
}
}
protected void lbtnLast_Click(object sender, EventArgs e)
{
try
{
lblMsg.Text = "";
gvExpenseList.PageIndex = gvExpenseList.PageCount - 1;
hdnPageIndex.Value = Convert.ToString(gvExpenseList.PageIndex);
GetData();
}
catch (Exception ex)
{
lblMsg.Visible = true;
lblMsg.Text = strErrorOnCatch;
unistanzSendEmail.SendEmailForError(strSMTPServer, strFromEmailAddress, strSubjectofSupportMail + " at BindData Subroutin", ex.Message + "<br /><br /><br />" + ex.StackTrace + "<br /><br /><br />", strToEmailAddress, strCCEmailAddress, "");
}
}
protected void btnGo_Click(object sender, EventArgs e)
{
try
{
lblMsg.Text = "";
gvExpenseList.PageIndex = 0;
hdnSearchby.Value = Request.Form["ctl00$Main$ddlSrchBy"];
hdnddlStatus.Value = Request.Form["ctl00$Main$ddlStatus"];
hdnSrchFromdate.Value = Request.Form["ctl00$Main$txtFrom_Time"];
hdnSrchTodate.Value = Request.Form["ctl00$Main$txtTo_Time"];
GetData();
hdnPageIndex.Value = Convert.ToString(gvExpenseList.PageIndex);
}
catch (Exception ex)
{
lblMsg.Visible = true;
lblMsg.Text = strErrorOnCatch;
unistanzSendEmail.SendEmailForError(strSMTPServer, strFromEmailAddress, strSubjectofSupportMail + " at btnGo_Click event", ex.Message + "<br /><br /><br />" + ex.StackTrace + "<br /><br /><br />", strToEmailAddress, strCCEmailAddress, "");
}
}
public void getSubmittedby()
{
DataSet ldsList = new DataSet();
try
{
ddlSubmittedBy.Items.Clear();
mobjBll.ProcedureName = "getExpenseSubmittedBy";
mobjBll.ParametersList = gmarrParam;
ldsList = mobjBll.GetList();
if (ldsList.Tables[0].Rows.Count > 0)
{
ddlSubmittedBy.DataSource = ldsList;
ddlSubmittedBy.DataTextField = "Username";
ddlSubmittedBy.DataValueField = "Userid";
ddlSubmittedBy.DataBind();
}
ddlSubmittedBy.Items.Insert(0, new ListItem("All", "All"));
}
catch (Exception ex)
{
lblMsg.Visible = true;
lblMsg.Text = strErrorOnCatch;
unistanzSendEmail.SendEmailForError(strSMTPServer, strFromEmailAddress, strSubjectofSupportMail + " at getSubmittedby Method", ex.Message + "<br /><br /><br />" + ex.StackTrace + "<br /><br /><br />", strToEmailAddress, strCCEmailAddress, "");
}
}
public string getLinkDetails()
{
string link = String.Empty;
link = "?FromTime=" + txtFrom_Time.Text + "&ToTime=" + txtTo_Time.Text + "&SearchBy=" + ddlSrchBy.SelectedValue + "&SearchText=" + txtSrch.Text + "&SearchDate=" + txtSrchdate.Text + "&SearchReleaseDate=" + txtSrchReleasedate.Text + "&SubmitedBy=" + ddlSubmittedBy.SelectedValue + "&Status=" + ddlStatus.SelectedItem.Text;
return link;
}
}
please help me.....
MK