0

here's what i have in my datatable so far :

my output in datatable

then after i process it using below code, i got this output :

my output in datatable

    private void graphBtn_Click_1(object sender, EventArgs e)

        DataRow totalsRow = my_datatable.NewRow();
        foreach (DataColumn col in my_datatable.Columns)
        {
            int colTotal = 0;
            foreach (DataRow row in col.Table.Rows)
            {
                colTotal += Int32.Parse(row[col].ToString());
            }
            totalsRow[col.ColumnName] = colTotal;
        }
        my_datatable.Rows.Add(totalsRow);

but my expected output is to have something like this :

my expected output in datatable

where it calculate and display the number of resource separately, then sum up all instead of it directly add up all the number of resources.

1aliff
  • 435
  • 2
  • 5
  • 15
  • Why you aren't using stack.imgur.com? – Alex78191 May 29 '17 at 02:46
  • Sorry, I didn't know about that. Really quite new. Can't I use imgbb for image uploading? @alex78191 – 1aliff May 29 '17 at 02:49
  • You can, but I guess standard is better for saving forever.however, you can show full image in question instead of link. – Alex78191 May 29 '17 at 02:52
  • Why you aren't using entity framework? – Alex78191 May 29 '17 at 02:53
  • Entity framework is awful for performance. If your using it in a small app fine, but in larger apps that require speed I would stay away from it. – Kelly May 29 '17 at 02:59
  • You don't create new column for number of hits – Alex78191 May 29 '17 at 02:59
  • Hi, i re-edit my post my images. Sorry for my previous post. Thanks for your responses @Alex78191 – 1aliff May 29 '17 at 03:03
  • Yea I didnt create the column for 'hits', yet. I just want to know if there is any ways to calculate it separately... – 1aliff May 29 '17 at 03:05
  • @AliffM. You need to sort your data in database itself dont do the data calculations at view side of app if you dont need it. Create all data at database and then get it in to datatable and show it on grid. And if you want to use EF then it provides lot of options to create required data view you need. – Mahesh May 29 '17 at 03:13
  • 1
    @AliffM. alternatively you can do the dataTable.AsEnumerable() and then write the lambda expression to get the data as given in this answer https://stackoverflow.com/a/19407930/643104 and at the end just bind the datagrid to datatable – Mahesh May 29 '17 at 03:19
  • I will definitely try it, thank you for you reply! @CoderofCode – 1aliff May 29 '17 at 03:40

0 Answers0