Kanhialal kk

Kanhialal kk

  • NA
  • 234
  • 338.6k

Error in getting record in crystal report

Oct 6 2012 4:25 AM
Hi ..
I am working on desktop application using C# visual studio 2005.
i am working on crystal report so while i fetch data from database then i getting error as bello

There is no row at position 0.

bellow is my code which i am using and error point is bold

this.b = 0;
            double num1 = 0.0;
            double num2 = 0.0;
            try
            {
                if (this.con.State == ConnectionState.Closed)
                    this.con.Open();
                this.ds1 = new DataTable();
                this.ds2 = new DataTable();
                this.ds3 = new DataTable();
                this.ds4 = new DataTable();
                this.ds5 = new DataSet();
                this.ds11 = new DataTable();
                this.ds12 = new DataTable();
                this.ds = new DataSet();
                this.dsnew = new DataSet();
                bool flag = false;
                this.sqlcmd = new SqlCommand();
                this.sqlcmd.Connection = this.con;
                this.sqlcmd.CommandText = "select sum(debit)-sum(credit),ahaccountid from trialbalancesummary where (ahaccountid like '1%' or ahaccountid like '5%') and ahaccountid not like '1009%'  group by ahaccountid order by ahaccountid ";
                this.adp = new SqlDataAdapter();
                this.adp.SelectCommand = this.sqlcmd;
                this.adp.Fill(this.ds1);
                this.sqlcmd.CommandText = "select sum(credit)-sum(debit),ahaccountid from trialbalancesummary where ahaccountid like '2%' or ahaccountid like '3%' or ahaccountid like '4%' or ahaccountid like '1009%'  group by ahaccountid order by ahaccountid ";
                this.adp.Fill(this.ds2);
                this.sqlcmd.CommandText = "select sum(debit)-sum(credit),ahaccountid from trialbalancesummary where ( foliodate <= '" + this.dateTimePicker1.Value.ToShortDateString() + "') and  ( ahaccountid like '1%' or ahaccountid like '5%') and ahaccountid not like '1009%'  group by ahaccountid order by ahaccountid ";
                this.adp.Fill(this.ds11);
                this.sqlcmd.CommandText = "select sum(credit)-sum(debit),ahaccountid from trialbalancesummary where ( foliodate <= '" + this.dateTimePicker1.Value.ToShortDateString() + "') and  ( ahaccountid like '2%' or ahaccountid like '3%' or ahaccountid like '4%' or ahaccountid like '1009%') group by ahaccountid order by ahaccountid ";
                this.adp.Fill(this.ds12);
                this.sqlcmd.CommandText = "Select Opendebit-Opencredit,Accountid from AccountHead where (accountid like '1%' or accountid like '5%') and mastercode not like '1009%' order by Accountid";
                this.adp.SelectCommand = this.sqlcmd;
                this.adp.Fill(this.ds3);
                this.sqlcmd.CommandText = "Select Opencredit-Opendebit,Accountid from AccountHead where accountid like '2%' or accountid like '3%' or accountid like '4%'  or mastercode like '1009%' order by Accountid";
                this.adp.SelectCommand = this.sqlcmd;
                this.adp.Fill(this.ds4);
                this.sqlcmd.CommandText = "Select *  from Accounthead order by accountid ";
                this.sqladp.SelectCommand = this.sqlcmd;
                ((DataAdapter)this.sqladp).Fill((DataSet)this.ds61);
                for (int index = 0; index <= this.ds1.Rows.Count - 1; ++index)
                    this.ds1.Rows[index][0] = (object)0;
                for (int index = 0; index <= this.ds2.Rows.Count - 1; ++index)
                    this.ds2.Rows[index][0] = (object)0;
                for (int index1 = 0; index1 <= this.ds11.Rows.Count - 1; ++index1)
                {
                    for (int index2 = 0; index2 <= this.ds1.Rows.Count - 1; ++index2)
                    {
                        if (this.ds11.Rows[index1][1].Equals(this.ds1.Rows[index2][1]))
                        {
                            this.ds1.Rows[index2][0] = this.ds11.Rows[index1][0];
                            break;
                        }
                    }
                }
                for (int index1 = 0; index1 <= this.ds12.Rows.Count - 1; ++index1)
                {
                    for (int index2 = 0; index2 <= this.ds2.Rows.Count - 1; ++index2)
                    {
                        if (this.ds12.Rows[index1][1].Equals(this.ds2.Rows[index2][1]))
                        {
                            this.ds2.Rows[index2][0] = this.ds12.Rows[index1][0];
                            break;
                        }
                    }
                }
                int index3 = 0;
                for (int index1 = 0; index1 <= this.ds3.Rows.Count - 1; ++index1)
                {
                    string str = Convert.ToString(this.ds3.Rows[index1][1]);
                    if (str.Substring(0, 1).Equals("1"))
                    {
                        if ((int)Convert.ToInt16(str.Substring(0, 4)) > 1008)
                        {
                            for (this.b = this.b; this.b <= this.ds2.Rows.Count - 1 && (int)Convert.ToInt16(Convert.ToString(this.ds2.Rows[this.b][1]).Substring(0, 4)) <= 1009; ++this.b)
                            {
                                if (this.ds2.Rows[this.b][0] is DBNull)
                                {
                                    this.ds61.Tables[0].Rows[index3][4] = (object)(Convert.ToDouble(0) + Convert.ToDouble(this.ds4.Rows[this.b][0]));
                                    ++index3;
                                }
                                else
                                {
                                    this.ds61.Tables[0].Rows[index3][4] = (object)(Convert.ToDouble(this.ds2.Rows[this.b][0]) + Convert.ToDouble(this.ds4.Rows[this.b][0]));
          
                          ++index3;
                                }
                            }
                        }
                        if (this.ds1.Rows[index1][0] is DBNull)
                        {
                            this.ds61.Tables[0].Rows[index3][4] = (object)(Convert.ToDouble(0) + Convert.ToDouble(this.ds3.Rows[index1][0]));
                            ++index3;
                        }
                        else
                        {
                            this.ds61.Tables[0].Rows[index3][4] = (object)(Convert.ToDouble(this.ds1.Rows[index1][0]) + Convert.ToDouble(this.ds3.Rows[index1][0]));
                            ++index3;
                        }
                    }
                    else if (str.Substring(0, 1).Equals("5"))
                    {
                        if (!flag)
                        {
                            for (this.b = this.b; this.b <= this.ds2.Rows.Count - 1; ++this.b)
                            {
                                if (this.ds2.Rows[this.b][0] is DBNull)
                                {
                                    this.ds61.Tables[0].Rows[index3][4] = (object)(Convert.ToDouble(0) + Convert.ToDouble(this.ds4.Rows[this.b][0]));
                                    ++index3;
                                }
                                else
                                {
                                    if (Convert.ToString(this.ds61.Tables[0].Rows[index3][0]).Substring(0, 1).Equals("4"))
                                        num2 += Convert.ToDouble(this.ds2.Rows[this.b][0]) + Convert.ToDouble(this.ds4.Rows[this.b][0]);
                                    this.ds61.Tables[0].Rows[index3][4] = (object)(Convert.ToDouble(this.ds2.Rows[this.b][0]) + Convert.ToDouble(this.ds4.Rows[this.b][0]));
                                    ++index3;
                                }
                            }
                            flag = true;
                            --index1;
                        }
                        else if (this.ds1.Rows[index1][0] is DBNull)
                        {
                            this.ds61.Tables[0].Rows[index3][4] = (object)(Convert.ToDouble(0) + Convert.ToDouble(this.ds3.Rows[index1][0]));
                            ++index3;
                        }
                        else
                        {
                            num1 += Convert.ToDouble(this.ds1.Rows[index1][0]) + Convert.ToDouble(this.ds3.Rows[index1][0]);
                            this.ds61.Tables[0].Rows[index3][4] = (object)(Convert.ToDouble(this.ds1.Rows[index1][0]) + Convert.ToDouble(this.ds3.Rows[index1][0]));
                            ++index3;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                int num3 = (int)MessageBox.Show(ex.Message, "View Info");
            }
            finally
            {
                this.con.Close();
            }
            int index4 = 0;
            for (int index1 = 0; index1 <= this.ds61.Tables[0].Rows.Count - 1; ++index1)
                this.ds61.Tables[0].Rows[index1][7] = (object)(num2 - num1);
            foreach (DataRow dataRow in (InternalDataCollectionBase)this.ds61.Tables[0].Rows)
            {
                string str = Convert.ToString(this.ds61.Tables[0].Rows[index4][0]);
                if (str.Substring(0, 1).Equals("4") || str.Substring(0, 1).Equals("5"))
                    this.ds61.Tables[0].Rows[index4].Delete();
                ++index4;
            }
            return (DataSet)this.ds61;

please help me

Answers (1)