When using CONCAT, I get an error saying "The input string does not have the correct format"

1

It turns out that data charges to DataTable in the following way:

private void cargarempresas()
{
    dt_hogar = new DataTable();
    String sql = "SELECT CAST(CONCAT(nombre,'-',apellido)AS CHAR) AS nombre,fechacreacion FROM hogar";
    conexion.conectar();
    datos = new MySqlDataAdapter(sql, conexion.con);
    conexion.cerrar();
    datos.Fill(dt_hogar);
    var source = new BindingSource();
    source.DataSource = dt_hogar ;
    Dtgempresas.DataSource = source;
}

And I update the DataTable in the following way:

private void btnActualizar_Click(object sender, EventArgs e)
{
    cmdbder = new MySqlCommandBuilder(datos);
    datos.Update(dt_hogar);
}

But the following error occurs:

  

The input string does not have the correct format.

To show the name and surname in a single column, I use the CONCAT , but it turns out, that when I use it, I get the error when updating, any idea show the first and last name together, without using the CONCAT so that I do not get an error when updating.

    
asked by Danilo 24.07.2017 в 07:34
source

1 answer

1

Execute:

SELECT CONCAT(nombre,'-',apellido) AS nombre, fechacreacion FROM hogar

Note that it does not have the CAST , probably some result comes NULL and it generates problems.

    
answered by 24.07.2017 в 18:32