Rajkumar R

Rajkumar R

  • NA
  • 183
  • 220k

data table sum function in asp.net

Nov 5 2011 5:59 AM
private void BindGrid()
    {
        // Set your connection String here
        SqlConnection cn = new SqlConnection("Data Source=.;Initial Catalog=Demo_eLogsVA4;Integrated Security=True");
        //Write a select Query
        cn.Open();
        string q = "Select Convert(nVarchar,A.Rec_No) CRec,A.Acc_Name Descr,A.Quantity Qty,Convert(nVarchar,A.Sell_Rate) SRate,Sell_CName Sname , Sell_CCode SCCode, Sell_CValue SCValue ,Convert(nVarchar,A.Quantity*A.Sell_Rate*Sell_CValue) SAmount, A.Service_Tax STax,Convert(nVarchar,(A.Quantity*A.Sell_Rate*Sell_CValue)* A.Service_Tax/100)Tax_Amount,Convert(nVarchar,((A.Quantity*A.Sell_Rate*Sell_CValue)+(A.Quantity*A.Sell_Rate*Sell_CValue)* A.Service_Tax/100)) Net From eLogs_Invoice_Charges_Details A Where A.Invoice_Code='INV991'";
        DataSet dset = new DataSet();
        SqlDataAdapter da = new SqlDataAdapter(q, cn);        
        DataTable dtable = new DataTable();
        da.Fill(dtable);
        //Bind grid.
        GridView1.DataSource = dtable;
        //object sumobject = Convert.ToInt32(dtable.Compute("SUM(Net)", ""));
        GridView1.DataBind();
        GridView1.FooterRow.Cells[10].Text = dset.Tables[0].Compute("sum(Net)", "").ToString();
        cn.Close();
    }

Here i m getting the following error
Exception Details: System.IndexOutOfRangeException: Cannot find table 0.
Plaese post the solution for me

Answers (2)