locked
insert List<List<object>> in datatable and then to sql table RRS feed

  • Question

  • Background story:

    I want to get data from influxdb and copy this data to sql table and I want to do this with a datatable.

    structure of the json file:

     public class Series
            {
                public string name { get; set; }
                public List<string> columns { get; set; }
                public List<List<object>> values { get; set; }
                public bool partial { get; set; }
            }

            public class Result
            {
                public int statement_id { get; set; }
                public Series[] series { get; set; }
            }

            public class Root
            {
                public List<Result> results { get; set; }
            }

    And this is the loop Iam building to get the columns and values:

                                                   

                foreach (var dataloop in root.results)
                {
                    for (int i = 0; i < countColumns; i++)
                    {
                        TestConsole.çolumn = dataloop.series[0].columns[i].ToString();
                        table.Columns.Add(TestConsole.çolumn);

                    }

                        for (int x = 0; x < countRows; x++)
                        {
                        DataRow row;

                            for (int y = 0; y < countColumns; y++)
                            {
                            row = table.NewRow();
                            row[table.Columns[y]] = (string)dataloop.series[0].values[x][y].ToString();
                            table.Rows.Add(row);
                            }
                        }




                }

    I can get the columns, but Iam stuck with the values... I try a lot of things but I cant understand why this wont work. Can someone give me a tip to solve this?


    Tuesday, December 29, 2020 10:14 AM

Answers

  • Eric,

    Maybe you did (although I can't verify that from you post history), but this is still the wrong forum. Try this one"

    https://social.msdn.microsoft.com/Forums/azure/en-US/home?forum=csharplanguage

    Admittedly, the TechNet forum are in a bit of flux as they apparently are being retired and everything will move to Microsoft Docs.

    John

    • Marked as answer by PWMatherMVP Tuesday, December 29, 2020 7:03 PM
    Tuesday, December 29, 2020 6:56 PM

All replies

  • Protecteric,

    Sorry but you have posted to a forum that deals exclusively with questions/issues about customizing and programming Microsoft Project, a project management application. I suggest you re-post to the following forum:

    https://docs.microsoft.com/en-us/answers/topics/c++.html

    John

    Tuesday, December 29, 2020 3:24 PM
  • John,

    Thanks for your answer, but this is a C# question and I posted my earlier questions also on this site.

    Best regards,

    Eric.

    I posted it here:

    C# insert List<List<object>> in datatable and then to sql - Microsoft Q&A



    • Edited by Protecteric Tuesday, December 29, 2020 6:56 PM
    Tuesday, December 29, 2020 5:59 PM
  • Eric,

    Maybe you did (although I can't verify that from you post history), but this is still the wrong forum. Try this one"

    https://social.msdn.microsoft.com/Forums/azure/en-US/home?forum=csharplanguage

    Admittedly, the TechNet forum are in a bit of flux as they apparently are being retired and everything will move to Microsoft Docs.

    John

    • Marked as answer by PWMatherMVP Tuesday, December 29, 2020 7:03 PM
    Tuesday, December 29, 2020 6:56 PM