I use the following code to load sql table values in datatable
DataTable dt = new DataTable();
SqlConnection con = new SqlConnection("Connection String Here");
con.Open();
SqlCommand cmd = new SqlCommand("select * from ExportExcel", con);
dt.Load(cmd.ExecuteReader());
int total = 0;
foreach (DataRow row in dt.Rows)
{
int salaryvalue = Convert.ToInt32(row["Salary"]);
total = salaryvalue + total;
}
dt.Rows.Add("Salary");
dt.Rows.Add(total);
And I add salary, dynamically dynamically. But she shows in the first column one by one.

But I need a salary in the Department column, and the total amount in the Salary column. How to do it?

source
share