I have a method to show a value in a TextBox
:
public double sumaEntregasDos(int id)
{
conectar();
//cmd2.CommandText = "SELECT SUM(pc.entrega) FROM PagosClientes pc INNER JOIN Clientes c ON pc.idCliente = c.idCliente WHERE c.nombre = @nombreCliente";
//cmd2.Parameters.AddWithValue("@nombreCliente", nombre);
cmd2.CommandText = "SELECT SUM(entrega) FROM PagosClientes WHERE idCliente in (" +
id + ")";
double suma = Convert.ToDouble(cmd2.ExecuteScalar());
desconectar();
return suma;
}
When I press the Button, the program shows me the following error:
Object cannot be cast from DBNull to other types.
How can I solve this problem?