Add a row under specific column in datatable

User

I Use the following code for load the sql table values into the 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,total dynamically.But It Shows in first column one by one.

enter image description here

But I need salary in Department column,and total in Salary Column.How to do this? enter image description here

Rohit

you can use

     dt.rows.add(new object[]{"","Salary",total });

Instead of calculating Total you can use Datatable.Compute Method

     object total;
      total= dt.Compute("Sum(Salary)", "");

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Find row in datatable with specific id

From Dev

Add column to a specific CSV row using Python pandas

From Dev

add button to datatable row dynamically

From Dev

Add a Link to a DataTable Column

From Dev

datatable get specific column from row

From Dev

How to find a row or column under specific conditions in a matrix in R

From Dev

Jquery UI Datatable: Add row to a table with textbox as column

From Dev

How to add image or a value in specific row in specific column

From Dev

Add text colour to a specific column name (header) in DT Shiny datatable

From Dev

Scroll to specific row in DataTable

From Dev

How to prevent row click function on specific column in datatable?

From Dev

Better way to add comma separated value to a datatable column when adding a new row in datatable

From Dev

How to add checkbox at specific row and column?

From Dev

jquery datatable add row undefined?

From Dev

Set value of each DataTable row in specific column

From Dev

Python Pandas - add column on a specific row, add specific row from one dataframe to another

From Dev

Find row in datatable with specific id

From Dev

Delete a specific row from datatable

From Dev

Can I add a header row under the column header row in JQGrid

From Dev

Add a column at the begining of datatable

From Dev

Finding a specific value in a datatable row

From Dev

Add a Link to a DataTable Column

From Dev

Datatable function for specific column

From Dev

How to find a row or column under specific conditions in a matrix in R

From Dev

How to add checkbox at specific row and column?

From Dev

Add column to dataframe depending on specific row values

From Dev

Add column to dataframe depending on specific row values (2)

From Dev

Get specific column foreach row in DataTable

From Dev

Angularjs datatable createdRow add class to specific row

Related Related

  1. 1

    Find row in datatable with specific id

  2. 2

    Add column to a specific CSV row using Python pandas

  3. 3

    add button to datatable row dynamically

  4. 4

    Add a Link to a DataTable Column

  5. 5

    datatable get specific column from row

  6. 6

    How to find a row or column under specific conditions in a matrix in R

  7. 7

    Jquery UI Datatable: Add row to a table with textbox as column

  8. 8

    How to add image or a value in specific row in specific column

  9. 9

    Add text colour to a specific column name (header) in DT Shiny datatable

  10. 10

    Scroll to specific row in DataTable

  11. 11

    How to prevent row click function on specific column in datatable?

  12. 12

    Better way to add comma separated value to a datatable column when adding a new row in datatable

  13. 13

    How to add checkbox at specific row and column?

  14. 14

    jquery datatable add row undefined?

  15. 15

    Set value of each DataTable row in specific column

  16. 16

    Python Pandas - add column on a specific row, add specific row from one dataframe to another

  17. 17

    Find row in datatable with specific id

  18. 18

    Delete a specific row from datatable

  19. 19

    Can I add a header row under the column header row in JQGrid

  20. 20

    Add a column at the begining of datatable

  21. 21

    Finding a specific value in a datatable row

  22. 22

    Add a Link to a DataTable Column

  23. 23

    Datatable function for specific column

  24. 24

    How to find a row or column under specific conditions in a matrix in R

  25. 25

    How to add checkbox at specific row and column?

  26. 26

    Add column to dataframe depending on specific row values

  27. 27

    Add column to dataframe depending on specific row values (2)

  28. 28

    Get specific column foreach row in DataTable

  29. 29

    Angularjs datatable createdRow add class to specific row

HotTag

Archive