System.DataRowView Error loading ComboBox C #

1

I have the same problem friends, I understand how the DataTable works but when I'm trying to load a ComboBox through a query that contains 2 tables it shows me the System.DataRowView

private void CargarComboCentrales()
{
    DataTable dt = null;
    string query = "";
   query = @"SELECT C.idCentral, E.nombreEdificio
            FROM Centrales C INNER JOIN Edificios E
            ON C.idEdificio=E.idEdificio
            ORDER BY E.nombreEdificio";

    if (Auxiliar.conexion.SqlSelectDataTable(query, ref dt))
    {
        cmbIdCentral.ValueMember = "C.idCentral";
        cmbIdCentral.DisplayMember = "E.nombreEdificio";
        cmbIdCentral.DataSource = dt;
    }

}

When I run the query in SQLServer it works very well. And I do not see any examples of loading combobox through an inner join.

If someone helps me, I would really appreciate it. PD: * When the information is in the same table if you load the combo without problems.

Tables >

Buildings:

idEdificio
nombreEdificio
zonaEdificio
direccion

Centrals:

idCentral
idEdificio
extension
marca
modelo

I would like to load the idCentral with the name of the building

Greetings!

    
asked by Nor 20.06.2018 в 07:50
source

1 answer

0

Assuming you have debugged and you see that the content of the DataTable is correct, I would do the following:

if (Auxiliar.conexion.SqlSelectDataTable(query, ref dt))
{
    cmbIdCentral.DataSource = dt;
    //Supongo que hasta aquí la variable dt contiene los valores necesarios
    cmbIdCentral.ValueMember = "idCentral";
    cmbIdCentral.DisplayMember = "nombreEdificio";

}

I get the impression that by using the names you give the tables in the query ( C.idCentral and E.nombreEdificio ) is not recognizing the names of the columns of the result.

Try this and tell me.

    
answered by 20.06.2018 / 08:15
source