be done and deserializar json then load it in DataGridView

0

I'm serializing and I want to undo a datagridview inside and I can not find the way ..

private void Json()
{
    string sql = @"SELECT 
                        cod,
                        Format(fecha, 'Short Date') as fecha,
                        Format(hora, 'Short Time') as hora,
                        1 as Tipo
                    FROM Registro";


        OleDbDataAdapter d = new OleDbDataAdapter(sql, connection);
        DataTable dt = new DataTable();
        d.Fill(dt);

        dataGridView1.DataSource = dt;

        var json = JsonConvert.SerializeObject(dt);

        List<DatosModel> asis = new List<DatosModel>();
        asis = JsonConvert.DeserializeObject<List<DatosModel>>(json);
        dataGridView2.DataSource = asis;
}

Model

private class DatosModel
{
    public int cod { get; set; }
    public DateTime fecha { get; set; }
    public DateTime hora { get; set; }
    public int Tipo { get; set; }
}

My json:

{"Table":[
{"cod":46897,"fecha":"6/3/2018","hora":"10:34","Tipo":1},{"cod":46929,"fecha":"6/3/2018","hora":"10:35","Tipo":1},{"cod":46972,"fecha":"6/3/2018","hora":"10:35","Tipo":1}
]}
    
asked by 12.03.2018 в 15:43
source

1 answer

0

as it is a string Json I recommend that you use all string types ( string )

Model

private class DatosModel
{
    public int cod { get; set; }
    public string fecha { get; set; }
    public string hora { get; set; }
    public int Tipo { get; set; }
}
    
answered by 20.03.2018 / 14:41
source