Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

Convert Json file of Arrays to Data Table then to DataView. Not working

I am attempting to Create a datATable in C# from a json string.

   {
        "Chamber":[99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99,99],
        "Name":["Zone","Zone","Zone","Zone","Zone","Zone","Zone","Zone","Zone","Zone","Zone","Zone","Zone","Zone","Zone","Zone","Zone","Zone","Zone","Zone","Zone","Zone","Zone","Zone","Zone","Zone","Zone","Zone","Zone","Zone","Zone","Zone"],
        "Type":["Temp","Temp","Temp","Temp","Temp","Temp","Temp","Temp","Temp","Temp","Temp","Temp","Temp","Temp","Temp","Temp","Temp","Temp","Temp","Temp","Temp","Temp","Temp","Temp","Temp","Temp","Temp","Temp","Temp","Temp","Temp","Temp"],
        "Unit":["c","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c","c"],
        "Value":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
    }

I am deserializing it using newtonsoft then Creating a DataTable and Setting my dataGridView datasource to that table. For some unknown reason it creates all the columns but does write to the data table. This is my First Time using data tables so I am very inexperienced. Any help would be vastly appreciated.

DataTable dt = (DataTable)JsonConvert.DeserializeObject(obj, (typeof(DataTable)));


           dt.Columns.Add("Chamber",
                System.Type.GetType("System.String"));
            dt.Columns.Add("Name",
                System.Type.GetType("System.String"));
            dt.Columns.Add("Type",
                System.Type.GetType("System.String"));
            dt.Columns.Add("Unit",
                System.Type.GetType("System.String"));
            dt.Columns.Add("Value",
                System.Type.GetType("System.String"));

            for (int i = 0; i < dt.Columns.Count; i++)
            {
                dt.Columns[i].AllowDBNull = false;
            }

            dataGridView1.DataSource = dt;

Comments