The input string does not have the correct format c #

-2

This is a program to show several products through the arrangement of objects. What happens is that when I am adding products with their respective attributes, I get an error saying "The input string does not have the correct format" pointing to this part that belongs to the Insert button:

private void btnInsertar_Click(object sender, EventArgs e)
{
        **producto.Ingresadatos(int.Parse(txtCodigo.Text), txtNombre.Text, double.Parse(txtCantidad.Text),txtUMedida.Text,double.Parse(txtCosto.Text));**
        txtCodigo.Clear(); txtNombre.Clear(); txtCantidad.Clear(); txtUMedida.Clear(); txtCosto.Clear();txtCodigo.Focus();
 }

This is the class code:

 int i, I,c1,c2,codigo;
    string nombre, unidadMe,salida;
    double costo,cantidad,cantMax,cantMin;

    Producto[] prod = new Producto[20];

    public void Ingresadatos(int cod,string nom,double cant,string uniMe,double cos)
    {

        prod[i] = new Producto();
        prod[i].codigo = cod;
        prod[i].nombre = nom;
        prod[i].cantidad = cant;
        prod[i].unidadMe = uniMe;
        prod[i].costo = cos;
    }
    public string Listar()
    {
        i++; I = i;
        for (i=0;i<I;i++)
        {
            salida+= " " + prod[i].codigo + " " + prod[i].nombre +
                " " + prod[i].cantidad +" "+ prod[i].unidadMe + " " + prod[i].costo + "\r\n";
        }
        return salida;
    }
    
asked by Darian Ganz 04.11.2018 в 20:48
source

1 answer

0

Probably one of the 2 variables to which you are doing the Parse, try to use a Try Parse instead of a Parse and share the output, with this code will try to Parse and otherwise we will set the value to 0 , so we will know which variable in particular is giving you the error, regards

int valor = 0;

int.TryParse(unacarga.tbCarga.Text, out valor );

datos[i] = valor;
    
answered by 04.11.2018 в 21:36