Index was outside the bounds of the array.

Last Reply 14 days ago By dharmendr

Posted 14 days ago

Dear SIr,

i have getting error "Index was outside the bounds of the array."

.aspx
<%@ Page Language="C#" AutoEventWireup="true" Codefile="show.aspx.cs" Inherits="showdata.fin" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <br />
        <br />
     <table border="0" cellpadding="5" cellspacing="0" align="center" class="auto-style29">
     
            <tr>
                <td class="auto-style25" colspan="8"><strong>Finance Dash Board</strong></td>
            </tr>
            <tr>
                <td class="auto-style27" colspan="7">
                    
                     &nbsp;</td>
                <td class="auto-style28">
                    
                     <asp:DropDownList ID="ddlCustomers" runat="server" AutoPostBack = "true" OnSelectedIndexChanged="ddlCustomers_SelectedIndexChanged">
        </asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td class="auto-style27" colspan="7">
                    
                     &nbsp;</td>
                <td class="auto-style28">As on:-&nbsp;&nbsp; <asp:Label ID="lbl50" runat="server" CssClass="auto-style26" />
                </td>
            </tr>
          <tr bgcolor="#FFA500">
                <td class="auto-style14" colspan="8"><strong><span class="auto-style22">Construction</span></strong></td>
            </tr>
         <tr bgcolor="#FFA500">
                <td class="auto-style18" colspan="8"><strong>&nbsp; </strong>Amount/Crore</td>
            </tr>
           <tr bgcolor="#FFA500">
                <td class="auto-style14">P<strong>articulars</strong></td>
                <td class="auto-style8"><strong>Amount/Crore</strong></td>
                <td class="auto-style21">&nbsp;</td>
                <td colspan="2" class="auto-style15"><strong>Particulars</strong></td>
                <td colspan="2" class="auto-style5"><strong>Original Cost </strong> </td>
                <td class="auto-style8"><strong class="auto-style18">Revised Cost</strong></td>
            </tr>
          <tr bgcolor="#FFA500">
                <td class="auto-style24">Total Capex (Provisional)</td>
                <td class="auto-style8">
                    <asp:Label ID="lbl" runat="server" />
                </td>
                <td class="auto-style21">&nbsp;</td>
                <td colspan="2" class="auto-style17">DCO</td>
                <td colspan="2" class="auto-style32">
                    <asp:Label ID="lbl6" runat="server" CssClass="auto-style19" />
                </td>
                <td class="auto-style32">
                    <asp:Label ID="lbl12" runat="server" CssClass="auto-style20" />
                </td>
            </tr>
            <tr bgcolor="#FFA500">
                <td class="auto-style24">Debt</td>
                <td class="auto-style8">
                    <asp:Label ID="lbl0" runat="server" />
                </td>
                <td class="auto-style21">&nbsp;</td>
                <td colspan="2" class="auto-style17">COMMG EXPENSES</td>
                <td colspan="2" class="auto-style32">
                    <asp:Label ID="lbl7" runat="server" />
                </td>
                <td class="auto-style32">
                    <asp:Label ID="lbl13" runat="server" />
                </td>
            </tr>
            <tr bgcolor="#FFA500">
                <td class="auto-style24">PFC</td>
                <td class="auto-style8">
                    <asp:Label ID="lbl1" runat="server" />
                </td>
                <td class="auto-style21">&nbsp;</td>
                <td colspan="2" class="auto-style17">IEDC and Consultancy</td>
                <td colspan="2" class="auto-style32">
                    <asp:Label ID="lbl8" runat="server" />
                </td>
                <td class="auto-style32">
                    <asp:Label ID="lbl14" runat="server" />
                </td>
            </tr>
           <tr bgcolor="#FFA500">
                <td class="auto-style24">ECB-SBI Tokyo</td>
                <td class="auto-style8">
                    <asp:Label ID="lbl2" runat="server" />
                </td>
                <td class="auto-style21">&nbsp;</td>
                <td colspan="2" class="auto-style17">IDC &amp; WCM</td>
                <td colspan="2" class="auto-style32">
                    <asp:Label ID="lbl9" runat="server" />
                </td>
                <td class="auto-style32">
                    <asp:Label ID="lbl15" runat="server" />
                </td>
            </tr>
           <tr bgcolor="#FFA500">
                <td class="auto-style24">Equity</td>
                <td class="auto-style8">
                    <asp:Label ID="lbl3" runat="server" />
                </td>
                <td class="auto-style21">&nbsp;</td>
                <td colspan="2" class="auto-style17">CONTINGENCIES</td>
                <td colspan="2" class="auto-style32">
                    <asp:Label ID="lbl10" runat="server" />
                </td>
                <td class="auto-style32">
                    <asp:Label ID="lbl16" runat="server" />
                </td>
            </tr>
           <tr bgcolor="#FFA500">
                <td class="auto-style24">Debt Equity</td>
                <td class="auto-style8">
                    <asp:Label ID="lbl4" runat="server" />
                </td>
                <td class="auto-style21">&nbsp;</td>
                <td colspan="2" class="auto-style17">Total</td>
                <td colspan="2" class="auto-style32">
                    <asp:Label ID="lbl11" runat="server" />
                </td>
                <td class="auto-style32">
                    <asp:Label ID="lbl17" runat="server" />
                </td>
            </tr>
           <tr bgcolor="#FFA500">
                <td class="auto-style24">PNB-Working Capital Loan</td>
                <td class="auto-style8">
                    <asp:Label ID="lbl5" runat="server" />
                </td>
                <td class="auto-style21">&nbsp;</td>
                <td colspan="2" class="auto-style15">&nbsp;</td>
                <td colspan="2">&nbsp;</td>
                <td class="auto-style5">&nbsp;</td>
            </tr>
            <tr>
                <td colspan="8">&nbsp;</td>
            </tr>
             <tr bgcolor="#9370DB">
                <td colspan="8"><strong class="auto-style22">Operations</strong></td>
            </tr>
             <tr bgcolor="#9370DB">
                <td colspan="3" class="auto-style23"><strong>Provisional Profitability</strong></td>
                <td colspan="3" class="auto-style13">From</td>
                <td colspan="2" class="auto-style12">To</td>
            </tr>
          <tr bgcolor="#9370DB">
                <td colspan="3">&nbsp;</td>
                <td colspan="3">
                    <asp:Label ID="lbl18" runat="server" CssClass="auto-style30" />
                </td>
                <td colspan="2">
                    <asp:Label ID="lbl19" runat="server" CssClass="auto-style31" />
                </td>
            </tr>
            <tr bgcolor="#9370DB">
                <td colspan="3" class="auto-style10"><strong>Particulars</strong></td>
                <td colspan="3"><b>Amount/crore</b></td>
                <td colspan="2" class="auto-style11">INR Per Unit</td>
            </tr>
             <tr bgcolor="#9370DB">
                <td colspan="3">&nbsp;</td>
                <td colspan="3">&nbsp;</td>
                <td colspan="2">&nbsp;</td>
            </tr>
             <tr bgcolor="#9370DB">
                <td colspan="3"><b>Revenue</b></td>
                <td colspan="3">
                    <b>
                    <asp:Label ID="lbl21" runat="server" />
                    </b>
                </td>
                <td colspan="2">
                    <b>
                    <asp:Label ID="lbl22" runat="server" />
                    </b>
                </td>
            </tr>
            <tr bgcolor="#9370DB">
                <td colspan="3"><b>Expenses</b></td>
                <td colspan="3">
                    <b>
                    <asp:Label ID="lbl23" runat="server" />
                    </b>
                </td>
                <td colspan="2">
                    <b>
                    <asp:Label ID="lbl24" runat="server" />
                    </b>
                </td>
            </tr>
             <tr bgcolor="#9370DB">
                <td colspan="3"><b>Fuel Cost</b></td>
                <td colspan="3">
                    <b>
                    <asp:Label ID="lbl25" runat="server" />
                    </b>
                </td>
                <td colspan="2">
                    <b>
                    <asp:Label ID="lbl26" runat="server" />
                    </b>
                </td>
            </tr>
             <tr bgcolor="#9370DB">
                <td colspan="3"><b>Employee Exp</b></td>
                <td colspan="3">
                    <b>
                    <asp:Label ID="lbl27" runat="server" />
                    </b>
                </td>
                <td colspan="2">
                    <b>
                    <asp:Label ID="lbl28" runat="server" />
                    </b>
                </td>
            </tr>
            <tr bgcolor="#9370DB">
                <td colspan="3"><b>Finance costs</b></td>
                <td colspan="3">
                    <b>
                    <asp:Label ID="lbl29" runat="server" />
                    </b>
                </td>
                <td colspan="2">
                    <b>
                    <asp:Label ID="lbl30" runat="server" />
                    </b>
                </td>
            </tr>
            <tr bgcolor="#9370DB">
                <td colspan="3"><b>Depreciation</b></td>
                <td colspan="3">
                    <b>
                    <asp:Label ID="lbl31" runat="server" />
                    </b>
                </td>
                <td colspan="2">
                    <b>
                    <asp:Label ID="lbl32" runat="server" />
                    </b>
                </td>
            </tr>
             <tr bgcolor="#9370DB">
                <td colspan="3"><b>Other Expenses</b></td>
                <td colspan="3">
                    <b>
                    <asp:Label ID="lbl33" runat="server" />
                    </b>
                </td>
                <td colspan="2">
                    <b>
                    <asp:Label ID="lbl34" runat="server" />
                    </b>
                </td>
            </tr>
             <tr bgcolor="#9370DB">
                <td colspan="3"><b>Total expenses </b> </td>
                <td colspan="3">
                    <b>
                    <asp:Label ID="lbl35" runat="server" />
                    </b>
                </td>
                <td colspan="2">
                    <b>
                    <asp:Label ID="lbl36" runat="server" />
                    </b>
                </td>
            </tr>
              <tr bgcolor="#9370DB">
                <td colspan="3"><b>Profit/ (Loss) Before Tax</b></td>
                <td colspan="3">
                    <b>
                    <asp:Label ID="lbl37" runat="server" />
                    </b>
                </td>
                <td colspan="2">
                    <b>
                    <asp:Label ID="lbl38" runat="server" />
                    </b>
                </td>
            </tr>
            <tr bgcolor="#9370DB">
                <td colspan="8">&nbsp;</td>
            </tr>
            <tr>
                <td colspan="8">&nbsp;</td>
            </tr>
             <tr bgcolor="#3CB371">
                <td colspan="4"><strong>Total Generation (MU)</strong></td>
                <td colspan="4">
                    <b>
                    <asp:Label ID="lbl39" runat="server" />
                    </b>
                </td>
            </tr>
           <tr bgcolor="#3CB371">
                <td colspan="4"><b>Cummulative Billing (INR/Crore)</b></td>
                <td colspan="4">
                    <b>
                    <asp:Label ID="lbl40" runat="server" />
                    </b>
                </td>
            </tr>
            <tr bgcolor="#3CB371">
                <td colspan="4"><b>Cummulative Realisation (INR/Crore)</b></td>
                <td colspan="4">
                    <b>
                    <asp:Label ID="lbl41" runat="server" />
                    </b>
                </td>
            </tr>
             
                <td colspan="8">&nbsp;</td>
            </tr>
           <tr bgcolor="#FFA07A">
                <td colspan="8"><b>Loss in per unit from Normative Parameters</b></td>
            </tr>
         <tr bgcolor="#FFA07A">
                <td colspan="4"><b>i) 10kcl increase in heat rate </b></td>
                <td colspan="4"><b>
                    <asp:Label ID="lbl42" runat="server" />
                    </b></td>
            </tr>
            <tr bgcolor="#FFA07A">
                <td colspan="4"><b>ii) Increase of APC by 0. 01% </b></td>
                <td colspan="4"><b>
                    <asp:Label ID="lbl43" runat="server" />
                    </b></td>
            </tr>
             <tr bgcolor="#FFA07A">
                <td colspan="4"><b>iii) Increase of 0.1 ml/unit oil consump.</b></td>
                <td colspan="4"><b>
                    <asp:Label ID="lbl44" runat="server" />
                    </b></td>
            </tr>
            <tr bgcolor="#FFA07A">
                <td colspan="4"><b>Loss in AFC due to reduction in 1% availability on annual basis</b></td>
                <td colspan="4"><b>
                    <asp:Label ID="lbl45" runat="server" />
                    </b></td>
            </tr>
        </table>
    
    </div>
    </form>
    <p class="auto-style33">
        &nbsp;</p>
    <p class="auto-style33">
        <strong>This Website is Designed and Developed by IT department.</strong></p>
</body> </frameset>
</html>
.aspx.cs
using System;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace showdata
{
    public partial class fin : System.Web.UI.Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
                ddlCustomers.Items.Add(new ListItem("--Select As on Date--", ""));
                ddlCustomers.AppendDataBoundItems = true;
                String strConnString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
                {
                     String strQuery =  "SELECT as_on_date, total_capex, debt,pfc,ecb_sbi_tokyo,equity,debt_equity,pnb_working_capital_loan,dco,dco_r,commg_expenses,commg_expenses_r,iedc_consultancy,iedc_consultancy_r,idc_wcm,idc_wcm_r,contingencies,contingencies_r,total,total_r,date_from,date_to,revenue,revenue_inr,expenses,expenses_i,fuel_cost,fuel_cost_i,employee_exp,employee_exp_i,finance_costs,finance_costs_i,depreciation,depreciation_i,other_expenses,other_expenses_i,total_expenses,total_expenses_i,profit_loss_before_tax,profit_loss_before_tax_i,total_generation,cummulative_billing,cummulative_realisation,increase_heat_rate,increase_apc,increase_oil_consump,loss_in_afc FROM FinanceDashBoard ";
                    {
                SqlConnection con = new SqlConnection(strConnString);
                SqlCommand cmd = new SqlCommand();
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = strQuery;
                cmd.Connection = con;
                try
                
                        {
                            con.Open();
                            ddlCustomers.DataSource = cmd.ExecuteReader();
                            ddlCustomers.DataTextField = "as_on_date";
                         
                            ddlCustomers.DataBind();
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                        finally
                        {
                            con.Close();
                            con.Dispose();
                        }
                    }
                }

                {
                    using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ConnectionString))
                    {
                        using (SqlCommand cmd = new SqlCommand("SELECT TOP 1 as_on_date,total_capex, debt,pfc,ecb_sbi_tokyo,equity,debt_equity,pnb_working_capital_loan,dco,dco_r,commg_expenses,commg_expenses_r,iedc_consultancy,iedc_consultancy_r,idc_wcm,idc_wcm_r,contingencies,contingencies_r,total,total_r,date_from,date_to,revenue,revenue_inr,expenses,expenses_i,fuel_cost,fuel_cost_i,employee_exp,employee_exp_i,finance_costs,finance_costs_i,depreciation,depreciation_i,other_expenses,other_expenses_i,total_expenses,total_expenses_i,profit_loss_before_tax,profit_loss_before_tax_i,total_generation,cummulative_billing,cummulative_realisation,increase_heat_rate,increase_apc,increase_oil_consump,loss_in_afc  FROM FinanceDashBoard ORDER BY as_on_date DESC", con))
                        {
                            cmd.CommandType = CommandType.Text;
                            con.Open();
                            SqlDataReader dr = cmd.ExecuteReader();
                            {
                                if (dr.Read())
                                {
                                    this.lbl50.Text = dr[0].ToString();
                                    this.lbl.Text = dr[1].ToString();
                                    this.lbl0.Text = dr[2].ToString();

                                    this.lbl1.Text = dr[3].ToString();

                                    this.lbl2.Text = dr[4].ToString();
                                    this.lbl3.Text = dr[5].ToString();
                                    this.lbl4.Text = dr[6].ToString();
                                    this.lbl5.Text = dr[7].ToString();
                                    this.lbl6.Text = dr[8].ToString();
                                    this.lbl7.Text = dr[9].ToString();

                                    this.lbl8.Text = dr[10].ToString();
                                    this.lbl9.Text = dr[11].ToString();
                                    this.lbl10.Text = dr[12].ToString();
                                    this.lbl11.Text = dr[13].ToString();
                                    this.lbl12.Text = dr[14].ToString();
                                    this.lbl13.Text = dr[15].ToString();
                                    this.lbl14.Text = dr[16].ToString();
                                    this.lbl15.Text = dr[17].ToString();
                                    this.lbl16.Text = dr[18].ToString();
                                    this.lbl17.Text = dr[19].ToString();
                                    this.lbl18.Text = dr[20].ToString();
                                    this.lbl19.Text = dr[21].ToString();

                                   
                                    this.lbl21.Text = dr[23].ToString();
                                    this.lbl22.Text = dr[24].ToString();
                                    this.lbl23.Text = dr[25].ToString();
                                    this.lbl24.Text = dr[26].ToString();
                                    this.lbl25.Text = dr[27].ToString();
                                    this.lbl26.Text = dr[28].ToString();
                                    this.lbl27.Text = dr[29].ToString();
                                    this.lbl28.Text = dr[30].ToString();
                                    this.lbl29.Text = dr[31].ToString();
                                    this.lbl30.Text = dr[32].ToString();
                                    this.lbl31.Text = dr[33].ToString();
                                    this.lbl32.Text = dr[34].ToString();
                                    this.lbl33.Text = dr[35].ToString();
                                    this.lbl34.Text = dr[36].ToString();
                                    this.lbl35.Text = dr[37].ToString();
                                    this.lbl36.Text = dr[38].ToString();
                                    this.lbl37.Text = dr[39].ToString();
                                    this.lbl38.Text = dr[40].ToString();
                                    this.lbl39.Text = dr[41].ToString();


                                    this.lbl40.Text = dr[43].ToString();
                                    this.lbl41.Text = dr[44].ToString();
                                    this.lbl42.Text = dr[45].ToString();


                                    this.lbl43.Text = dr[46].ToString();
                                    this.lbl44.Text = dr[47].ToString();
                                    this.lbl45.Text = dr[48].ToString();
                                
                                 
                                    
                                }
                            }
                            con.Close();
                        }
                    }
                }
            }
        }
            
        
                protected void ddlCustomers_SelectedIndexChanged(object sender, EventArgs e)
                {
            String strConnString = ConfigurationManager
                                   .ConnectionStrings["constr"].ConnectionString;
            String strQuery = "select as_on_date, total_capex, debt,pfc,ecb_sbi_tokyo,equity,debt_equity,pnb_working_capital_loan,dco,dco_r,commg_expenses,commg_expenses_r,iedc_consultancy,iedc_consultancy_r,idc_wcm,idc_wcm_r,contingencies,contingencies_r,total,total_r,date_from,date_to,revenue,revenue_inr,expenses,expenses_i,fuel_cost,fuel_cost_i,employee_exp,employee_exp_i,finance_costs,finance_costs_i,depreciation,depreciation_i,other_expenses,other_expenses_i,total_expenses,total_expenses_i,profit_loss_before_tax,profit_loss_before_tax_i,total_generation,cummulative_billing,cummulative_realisation,increase_heat_rate,increase_apc,increase_oil_consump,loss_in_afc FROM FinanceDashBoard where" +
                      " as_on_date = @as_on_date";

       SqlConnection con = new SqlConnection(strConnString);
       SqlCommand cmd = new SqlCommand();
       cmd.Parameters.AddWithValue("@as_on_date", ddlCustomers.SelectedItem.Value);
       cmd.CommandType = CommandType.Text;
       cmd.CommandText = strQuery;
       cmd.Connection = con;
            try
            {   
                con.Open();
                SqlDataReader sdr = cmd.ExecuteReader();
                while (sdr.Read())
                {
                           
                            lbl50.Text = sdr["as_on_date"].ToString();
                            lbl.Text = sdr["total_capex"].ToString();
                            lbl0.Text = sdr["debt"].ToString();
                            lbl1.Text = sdr["pfc"].ToString();
                            lbl2.Text = sdr["ecb_sbi_tokyo"].ToString();
                            lbl3.Text = sdr["equity"].ToString();
                            lbl4.Text = sdr["debt_equity"].ToString();
                            lbl5.Text = sdr["pnb_working_capital_loan"].ToString();

                            lbl6.Text = sdr["dco"].ToString();
                            lbl7.Text = sdr["dco_r"].ToString();
                            lbl8.Text = sdr["commg_expenses"].ToString();
                            lbl9.Text = sdr["commg_expenses_r"].ToString();
                            lbl10.Text = sdr["iedc_consultancy"].ToString();
                            lbl11.Text = sdr["iedc_consultancy_r"].ToString();
                            lbl12.Text = sdr["idc_wcm"].ToString();
                            lbl13.Text = sdr["idc_wcm_r"].ToString();
                            lbl14.Text = sdr["contingencies"].ToString();
                            lbl15.Text = sdr["contingencies_r"].ToString();
                            lbl16.Text = sdr["total"].ToString();
                            lbl17.Text = sdr["total_r"].ToString();

                            lbl18.Text = sdr["date_from"].ToString();
                            lbl19.Text = sdr["date_to"].ToString();
                            lbl21.Text = sdr["revenue"].ToString();
                            lbl22.Text = sdr["revenue_inr"].ToString();
                            lbl23.Text = sdr["expenses"].ToString();
                            lbl24.Text = sdr["expenses_i"].ToString();
                            lbl25.Text = sdr["fuel_cost"].ToString();
                            lbl26.Text = sdr["fuel_cost_i"].ToString();
                            lbl27.Text = sdr["employee_exp"].ToString();
                            lbl28.Text = sdr["employee_exp_i"].ToString();
                            lbl29.Text = sdr["finance_costs"].ToString();
                            lbl30.Text = sdr["finance_costs_i"].ToString();
                            lbl31.Text = sdr["depreciation"].ToString();
                            lbl32.Text = sdr["depreciation_i"].ToString();
                            lbl33.Text = sdr["other_expenses"].ToString();
                            lbl34.Text = sdr["other_expenses_i"].ToString();
                            lbl35.Text = sdr["total_expenses"].ToString();
                            lbl36.Text = sdr["total_expenses_i"].ToString();
                            lbl37.Text = sdr["profit_loss_before_tax"].ToString();
                            lbl38.Text = sdr["profit_loss_before_tax_i"].ToString();


                            lbl39.Text = sdr["total_generation"].ToString();
                            lbl40.Text = sdr["cummulative_billing"].ToString();
                            lbl41.Text = sdr["cummulative_realisation"].ToString();


                            lbl42.Text = sdr["increase_heat_rate"].ToString();
                            lbl43.Text = sdr["increase_apc"].ToString();
                            lbl44.Text = sdr["increase_oil_consump"].ToString();
                            lbl45.Text = sdr["loss_in_afc"].ToString();
                            
                        }

  }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                con.Close();
                con.Dispose();
            }
        }
    }
}

 

 

You are viewing reply posted by: dharmendr 14 days ago.