Rajkumar R

Rajkumar R

  • NA
  • 183
  • 220k

How to sum a field in the data table

Nov 5 2011 3:17 AM
 SqlConnection cn = new SqlConnection("Data Source=.;Initial Catalog=Demo_eLogsVA4;Integrated Security=True");
        //Write a select Query
        cn.Open();
        string q = "Select Invoice_Code,Amount,Tax,Net Where 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;
        DataRow[] dr = dtable.Select("Sum(Net)");
        GridView1.FooterRow.Cells[0].Text = Convert.ToString(dr[0]);
        GridView1.DataBind();
        cn.Close();

the above is my gridbind method. My table name is dtable, from that dtable i want to sum the amount and net field in the datatable(dtable) and where i want to include the sum code ,Help please


Answers (12)