Do not fill my datagriview with linq

3

As a result of my first consultation in this forum, I was suggested to use EF, I am actually learning and it saves me a lot of time in terms of entities, but now I have this problem.

I have 4 Data Layers, Entity, Business and Presentation.

In my every Data I have

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entidad;

namespace Datos
{
    public class DPolizas
    {
        public List<POLIZAS> GetPolizas()
        {
                var Query = (from p in db.POLIZAS
                             select new POLIZAS
                             {
                                 ASE_CODIGO = p.ASE_CODIGO,
                                 CLI_CODIGO = p.CLI_CODIGO
                             }).ToList();

                return Query;
        }
    }
}

In my business layer I have

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entidad;
using Datos;

namespace Negocio
{
    public class NPolizas
    {
        public List<POLIZAS> GetPolizas()
        {
            DPolizas dPolizas = new DPolizas();
            return dPolizas.GetPolizas();

        }
    }
}

and I have a form with a datagriview and a button for the query and test my code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Entidad;
using Negocio;

namespace Rsa
{
    public partial class frmPolizas : Form
    {
        public frmPolizas()
        {
            InitializeComponent();
        }

        private void btnListar_Click(object sender, EventArgs e)
        {
           List<POLIZAS> lista = new List<POLIZAS>();
           NPolizas nPolizas = new NPolizas();
           lista = nPolizas.GetPolizas();
           dgvPolizas.DataSource = lista;
        }
    }
}

and when I press the List button it only shows me the header and it does not bring me data even though I have many records in this table ?? What am I doing wrong??

Now I get an error like this

Apparently says it can not find a connection string, however if I have app.conf

I really do not understand.

Thanks for any help you can give me.

    
asked by Guivan 12.09.2017 в 07:10
source

2 answers

2

Seeing your code what is really being done is assigning to your DGV an empty list. You should first fill out that list by calling your business component. How the method in business is static would not need to instantiate the class.

    private void btnListar_Click(object sender, EventArgs e)
    {
        List<POLIZAS> lista = NPolizas.GetPolizas(); // llamar a negocio
        dgvPolizas.DataSource = lista;
    }
    
answered by 12.09.2017 / 07:25
source
0

The app.config is missing in the main project, the connection must also go there

    
answered by 30.10.2018 в 23:47